env

package
v0.0.0-...-44808bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

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

View Source
const UNSET string = "__UNSET__"

UNSET is the string returned for values not found in env nor in Defaults either.

Variables

View Source
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.

View Source
var MBENV string = "life"

MBENV is the default env name.

View Source
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 Get

func Get(key string) string

Get key value, using Init copy for its default value. If not present, returns UNSET.

func GetBool

func GetBool(key string) bool

GetBool returns the bool value for key. If there's a parsing error it will be logged and return default value false.

func GetInt

func GetInt(key string) int

GetInt returns the int value for key. If there's a parsing error it will be logged and return default value 0.

func GetUint

func GetUint(key string) uint

GetUint returns the uint value for key. If there's a parsing error it will be logged and return default value 0.

func Set

func Set(key, val string)

Set sets env key value. But it does not modify os.Environ.

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.

func SetInt

func SetInt(key string, val int)

SetInt sets an int value.

func SetUint

func SetUint(key string, val uint)

SetUint sets an uint value.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL