Skip to content

Conversation

@MaxJa4
Copy link

@MaxJa4 MaxJa4 commented Aug 29, 2023

Closes #130

Exposing Lookup to the user enables them to use a custom LookupEnv function.
This way, any custom logic like the _FILE convention mentioned in #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)
}
...

@KenxinKun
Copy link

Any chance of this getting merged? I'd really could use this in my testing framework :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support emerging _FILE convention

2 participants