-
Notifications
You must be signed in to change notification settings - Fork 385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maps configuration with value including colon character #180
Comments
Hi
type MyMap map[string]string
type Config struct {
Schedule string
Port int
User string
Passwd string
Urls map[string]string
}
func (m *MyMap) Set(value string) error{
list := MyMap{}
regexSpliter := `[^\\]:`
reg, err := regexp.Compile(regexSpliter)
if err != nil {
return err
}
if len(strings.TrimSpace(value)) != 0 {
pairs := strings.Split(value, ",")
for _, pair := range pairs {
sepRange := reg.FindAllStringIndex(pair, -1)
if len(sepRange) != 1 {
return fmt.Errorf("invalid map item: %q", pair)
}
key := pair[0:sepRange[0][0]+1]
val := strings.Replace(pair[sepRange[0][1]:], "\\:", ":", -1)
list[key]=val
}
}
*m = MyMap(list)
return nil
} |
this pr addresses #184 |
go-envconfig can override separator via |
Hi
The envconfig library is amazing. However, I've run into an issue where I cannot configure map of strings (
map[string]string
) where value contains colon character.Basically I am trying to keep a map of URLs like
dev:https://foo.com,prod:https://bar.com
.Configuration structure is as follows:
After calling
envconfig.Process
theUrls
property is empty. If I remove ':' from values, it works perfectly fine.Is there any workaround to that problem?
The text was updated successfully, but these errors were encountered: