Skip to content

1.5.0

Latest
Compare
Choose a tag to compare
@MaxJa4 MaxJa4 released this 29 Aug 09:31
· 2 commits to master since this release
6d65ebe

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)
}
...