Skip to content

Instantly share code, notes, and snippets.

@curlyz
Last active March 2, 2022 16:02
Show Gist options
  • Save curlyz/ccd399160f73a429999e6a1c59326dfc to your computer and use it in GitHub Desktop.
Save curlyz/ccd399160f73a429999e6a1c59326dfc to your computer and use it in GitHub Desktop.
awesome-go

Popular library

package.envconfig

github.com/kelseyhightower/envconfig
// first, define the structure
type CustomConfig struct {
    Targets []string `envconfig:"TARGETS" default:"SOMETHING"`
    Timeout time.Duration `envconfig:"TIMEOUT"`
}

// load the config
var conf CustomConfig
envconfig.Load(&conf)
envconfig.LoadWithPrefix("PREFIX", &conf)

func loadConfig(conf interface{}){
    if err := envconfig.Process("prefix", conf); err != nil {
        ...
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment