kelseyhightower / envconfig

Golang library for managing configuration data from environment variables
MIT License
5.01k stars 377 forks source link

allow maps of slices #209

Open strawhatguy opened 1 year ago

strawhatguy commented 1 year ago

Example: map[string][]int

This wasn't allowed before because the separator for map elements was the same as the separator for slice elements.

Allow custom processors to be configured to handle this, but also preserve the existing behavior. With proc := NewProcessor().WithMapSepChar(";"), an envvar set to foo:1,2,3;bar:4 can be parsed into a map[string][]int, for example

The usage also had to change, as it is no longer just commas. For this, use the actual values of the processor for simplicity.

strawhatguy commented 1 year ago

Just want to emphasize that a DefaultProcessor is created, so users can still call Process and MustProcess the same way as before, with the same results. Nothing changes in the parsing logic, which already could handle maps of slices.

Only for those that need the extra behavior would making a custom Processor be necessary. proc.Process and proc.MustProcess

I believe this preserves the simplicity of the existing code, while allowing others to change it as needed.