go-env icon indicating copy to clipboard operation
go-env copied to clipboard

Slice support

Open jimmykodes opened this issue 5 years ago • 3 comments

I would like to be able to define slices of data in my environment, and not have to do the extra work of processing the string into a slice after the env unmarshalling process.

An example use case would be defining BCC email addresses:

// env
[email protected]|[email protected]|[email protected]

// settings.go
type Settings struct {
    BCC []string `env:"BCC_EMAILS"`
}

Since this just piggy-backs off the existing type conversion process, slices of all supported types will also be supported.

jimmykodes avatar Dec 22 '20 22:12 jimmykodes

Hi @jimmykodes, I'm not sure about mixing commas for structtags delimiting and support for slice. Perhaps make the delimiter a parameter but I'm not sure how it will look.

hinshun avatar Feb 15 '21 18:02 hinshun

hey @hinshun been awhile since i've looked at this 😬 picking it back up again though. I've removed the "overloading" of the commas here and made the separator configurable by an environment variable. There may need to be some extra gymnastics to support that coming from the env set rather than a call to the os.Getenv, which i'm happy to go through if you'd like, and if this solution is a little more to your liking.

jimmykodes avatar Apr 22 '21 23:04 jimmykodes