Documentation ¶
Overview ¶
Package dotenv manages the configuration of the application through a .env file and environment variables.
The developer creates a .env file locally (and doesn't commit it to source control) with information about database connections, logging verbosity, and other settings he or she would like to override during development, and these settings will be loaded into environment variables when the application starts.
In production, the container or virtual machine OS environment variables may be configured per deployment to override any settings relevant to that specific environment. This leaves any containers free of configuration files and easily configured externally, as most container solutions provide configuration through environment variables.
Index ¶
- Constants
- Variables
- func Default(key string) (descriptor, bool)
- func GetBool(key string) bool
- func GetDuration(key string) time.Duration
- func GetFloat64(key string) float64
- func GetInt(key string) int
- func GetInt64(key string) int64
- func GetString(key string) string
- func GetStringSlice(key string) []string
- func Help()
- func Load() error
- func Register(key string, defaultValue interface{}, description string)
Constants ¶
const ( StringType = iota StringSliceType IntType Float64Type BoolType DurationType )
Variables ¶
var ( // ErrBadUserFile returned when the .env file in the user's home directory is invalid. ErrBadUserFile = errors.New("unable to parse $HOME/.env file") // ErrBadLocalFile returned when the local .env file (in the same directory as the app) is // invalid. ErrBadLocalFile = errors.New("unable to parse .env file") )
Functions ¶
func GetBool ¶
GetBool returns the environment variable as a boolean value. If the environment variable doesn't exist, returns the default value if present, otherwise returns false.
func GetDuration ¶
GetDuration returns the environment variable as an time.Duration value. If the environment variable doesn't exist, returns the default value if present, otherwise returns 0.
func GetFloat64 ¶
GetFloat64 returns the environment variable as an float64 value. If the environment variable doesn't exist, returns the default value if present, otherwise returns 0.
func GetInt ¶
GetInt returns the environment variable as an integer value. If the environment variable doesn't exist or is not an integer, returns the default value if present, otherwise returns 0.
func GetInt64 ¶ added in v0.3.0
GetInt64 returns the environment variable as an int64 value. If the environment variable doesn't exist or is not an int64, returns the default value if present, otherwise returns 0.
func GetString ¶
GetString returns the environment variable as a string value. If the environment variable doesn't exist, returns the default value if present, otherwise a blank string.
func GetStringSlice ¶
GetStringSlice returns the environment variable as a string slice value. If the environment variable doesn't exist, returns the default value if present, otherwise a nil value. Expects a environment variable value to be a comma-separated list of values.
func Help ¶
func Help()
Help displays details about registered default variables. May be called via a `--help` command-line parameter, or if some setting is invalid. Produces colorized output to stdout.
Types ¶
This section is empty.