kelseyhightower / envconfig

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

Support populating slice fields from environment variables #31

Closed mark-adams closed 8 years ago

mark-adams commented 8 years ago

Currently, environment variables can only be populated from basic primitives (int, float, string, bool, etc.). It'd be really useful if a user could take a comma-separated value given via an environment variable and populate it into a slice field on a struct.

For example, given the following struct:

type Specification struct {
    AdminUsers                   []string
    MagicNumbers                 []int

a user should be able to set ADMINUSERS = "john,joe,matt" in the environment and have the values populated into the Specification.AdminUsers field on the above struct as []string{"john", "joe", "matt"}

krhubert commented 8 years ago

checkout my repo, I wrote something for my project becouse I need this functionality, you can use it if you want https://github.com/krhubert/envconf

mark-adams commented 8 years ago

Thanks @krhubert! Hopefully @kelseyhightower will merge my PR here as well.