Skip to content

Commit

Permalink
Allow for space delimiters (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo authored Dec 1, 2022
1 parent 26382ce commit bddf2fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import (
"strconv"
"strings"
"time"
"unicode"
)

const (
Expand Down Expand Up @@ -452,7 +453,7 @@ func keyAndOpts(tag string) (string, *options, error) {

LOOP:
for i, o := range tagOpts {
o = strings.TrimSpace(o)
o = strings.TrimLeftFunc(o, unicode.IsSpace)
switch {
case o == optOverwrite:
opts.Overwrite = true
Expand Down
30 changes: 30 additions & 0 deletions envconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,36 @@ func TestProcessWith(t *testing.T) {
"URL": "https://foo.bar",
}),
},
{
// https://github.com/sethvargo/go-envconfig/issues/79
name: "space_delimiter",
input: &struct {
Field map[string]string `env:"FIELD,delimiter= "`
}{},
exp: &struct {
Field map[string]string `env:"FIELD,delimiter= "`
}{
Field: map[string]string{"foo": "1,2", "bar": "3,4", "zip": "zap:zoo,3"},
},
lookuper: MapLookuper(map[string]string{
"FIELD": "foo:1,2 bar:3,4 zip:zap:zoo,3",
}),
},
{
// https://github.com/sethvargo/go-envconfig/issues/79
name: "space_separator",
input: &struct {
Field map[string]string `env:"FIELD,separator= "`
}{},
exp: &struct {
Field map[string]string `env:"FIELD,separator= "`
}{
Field: map[string]string{"foo": "bar", "zip:zap": "zoo:zil"},
},
lookuper: MapLookuper(map[string]string{
"FIELD": "foo bar,zip:zap zoo:zil",
}),
},
}

for _, tc := range cases {
Expand Down

0 comments on commit bddf2fa

Please sign in to comment.