Documentation
¶
Overview ¶
Package conf provides cascading application configuration via environment variables and hardcoded defaults.
The recommended usage is to instantiate using conf.Basic(), passing default values:
config := conf.Basic(map[string]string{
"LISTEN_PORT": "8080",
"SQLITE_DB": "./devDatabase.db",
"MYSQL_DB": "mysql://test:test@localhost/test",
})
port := fmt.Sprintf(":%d", int(config.Get("LISTEN_PORT")))
mysqlUrl := config.Get("MYSQL_DB")
In this case, the config object will return values set in environment variables, if available. Otherwise, it will output a one-time warning on stderr for each requested configuration setting, and return the hardcoded default value.
This is exactly equivalent to the following:
config := conf.Chain(conf.Env(), conf.Warn(conf.Map(defaultValues)))
If your project is a library and you'd like to use this, you should require a ConfChain to be passed, and add your default values via Use. If your project is not a library, feel free to skip instantiation and make use of Get, Use and UseMap, all of which use the default Conf.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ConfChain ¶
ConfChain is a more powerful Conf instance that allows adding more default values in an existing instance. This can be useful when the Conf object is passed around.
func Basic ¶
Basic returns a Conf which attempts to return values set in environment variables. If no environment variable is set, the Conf will warn about this on stderr while returning the passed default value.
func Chain ¶
Chain provides cascading configuration by taking the first non-empty value from a slice of other Conf instances.
func Map ¶
Map will return the settings from the given map of default values. It is primarly used for providing default values as the end of a Chain.