Skip to content

Releases: offen/envconfig

1.5.0

29 Aug 09:31
6d65ebe
Compare
Choose a tag to compare

Exposing Lookup to the user enables them to use a custom LookupEnv function.
This way, any custom logic like the _FILE convention mentioned in kelseyhightower#130 can be supported on the application side.

Example taken and adapted from offen/docker-volume-backup:

envconfig.Lookup = func(key string) (string, bool) {
    location, ok := os.LookupEnv(key + "_FILE")
    if ok {
        contents, err := os.ReadFile(location)
        if err != nil {
            return "", false
        }
        return string(contents), true
    }
    return os.LookupEnv(key)
}

if err := envconfig.Process("", &config); err != nil {
    panic(err)
}
...