Documentation ¶
Overview ¶
Package env manages settings configurable from os.Environ and .env files.
Gets config settings from os.Environ or from Defaults otherwise. It will also load .env files if present.
Settings from .env file will be used to populate os.Environ at init() time.
If MBENV_CONFIG is set as "" (empty) no more files will be loaded, which is the default behavior.
But if file ${MBENV_CONFIG}/${MBENV}.env exists it will be loaded too.
Every loaded file overrides the settings from previous one.
Index ¶
Constants ¶
const UNSET string = "__UNSET__"
UNSET is the string returned for values not found in env nor in Defaults either.
Variables ¶
var Init map[string]string = map[string]string{
"MUNBOT": "master",
"MB_DEBUG": "false",
"MB_PROFILE": "default",
"MB_LOG": "verbose",
"MB_LOG_COLORS": "auto",
"MB_LOG_DEBUG": "",
"MB_HOME": "",
"MB_CONFIG": "",
"MB_RUN": "",
"MBAPI": "true",
"MBAPI_DEBUG": "false",
"MBAPI_NET": "tcp",
"MBAPI_ADDR": "127.0.0.1",
"MBAPI_PORT": "6490",
"MBAPI_PATH": "/",
"MBAUTH": "true",
"MBCONSOLE": "true",
"MBCONSOLE_ADDR": "0.0.0.0",
"MBCONSOLE_PORT": "6492",
}
Init contains the initial settings. They are copied at init(), so direct modifications to this map doesn't have any effect.
var MBENV string = "life"
MBENV is the default env name.
var MBENV_CONFIG string = ""
MBENV_CONFIG if set, should be a dir path where to look for ${MBENV}.env file. If it's set as "" (empty string) no extra files will be loaded (besides .env). By default it's set at init() time to ${HOME}/env if we can get user's home dir.
Functions ¶
func GetBool ¶
GetBool returns the bool value for key. If there's a parsing error it will be logged and return default value false.
func GetInt ¶
GetInt returns the int value for key. If there's a parsing error it will be logged and return default value 0.
func GetUint ¶
GetUint returns the uint value for key. If there's a parsing error it will be logged and return default value 0.
func SetDefault ¶
func SetDefault(key, val string)
SetDefault sets a default value. Env is not modified, the option is added to the default settings. If it already exists, its value is updated.
Types ¶
This section is empty.