Skip to content

ryanlower/setting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

setting

A simple utility to load your configuration from the environment (with optional defaults)

Circle CI

type Config struct {
  Port string `env:"PORT" default:"3000"`
}

config := new(Config)
setting.Load(config)

// If the PORT environment variable is set, `config.Port` will
// now be its value (`os.Getenv("PORT")`). Otherwise it will
// be "3000"

Both env and default are optional:

type Config struct {
  Name string `env:"NAME"`
  Location struct {
    City string `default:"San Francisco"`
  }
}

config := new(Config)
setting.Load(config)

// `config.Name` will be the NAME environment variable value if
// present, or the zero value if not
// `config.Location.City` will be "San Francisco"

Limitations

Setting currently only supports string type fields! If you need another type open an issue or a pull request 😄

About

Configuration via environment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages