configuration could be provided in different way (ordered by priority)
- ENV variables
- utilizing github.com/joho/godotenv
- it will try to load
.envfile in current executable directory - env prefix key defined via env var
GOCONF_ENV_PREFIX, if given, all loaded configuration via.envshould be prefixed - all configuration key could have a dot (.) which then translated into nested object
- File config
- configuration schema type defined via env var
GOCONF_TYPE, supported types:json,yaml,toml, if not defined, default value givenjson - configuration filename defined via env var
GOCONF_FILENAMEif not defined, default valueconfig - must exists in one of directory defined,
.,$HOME,/usr/local/etc,/etc
- configuration schema type defined via env var
- Remote config through consul
- consul host provided through env variable with key
GOCONF_CONSUL - configuration schema type defined via env var
GOCONF_TYPE, supported types:json,yaml,toml, if not defined, default value givenjson - configuration filename defined via env var
GOCONF_FILENAMEif not defined, default valueconfig - configuration defined in a single key named
/${GOCONF_FILENAME}
- consul host provided through env variable with key
Access from any part of codes:
- initialization done via
init(), ensure package loaded at the very top ofimportinmain(), to ensure its executed first before otherinit()which expected loaded config - utilizing library github.com/spf13/viper
- provided behaviour could be accessed through package methods or resolve viper instance through
Config()method