跳转至

Configuration

Package config is a complete configuration solution for Go applications. It is designed to work within an application, and can handle many types of configuration. It supports:

  • reading from JSON, YAML, TOML config files
  • reading from environment variables
  • reading from command line flags
  • reading from custom config source
  • reading from remote config systems (etcd or Consul) (TODO)
  • setting default values
  • setting explicit values

config can be thought of as a registry for all of your applications configuration needs.

Bind flags

config.BindFlags(app.Flags.Inner())

Bind environment variables

config.BindEnv("a.b", "A_B")

Custom configuration source

Unmarshal to struct