Documentation
¶
Overview ¶
Package env provides convenience functions for retrieving data from environment variables
Package env provides convenience functions for retrieving data from environment variables
Index ¶
- func AsBool(s string) bool
- func Bool(envName string) bool
- func Contains(envName string, value string) bool
- func Dir(name string, optionalDefault ...string) string
- func DurationHours(envName string, defaultValue int64) time.Duration
- func DurationMinutes(envName string, defaultValue int64) time.Duration
- func DurationSeconds(envName string, defaultValue int64) time.Duration
- func ExpandUser(path string) string
- func File(name string, optionalDefault ...string) string
- func Float32(envName string, defaultValue float32) float32
- func Float64(envName string, defaultValue float64) float64
- func Has(envName string) bool
- func HomeDir() string
- func Int(envName string, defaultValue int) int
- func Int16(envName string, defaultValue int16) int16
- func Int32(envName string, defaultValue int32) int32
- func Int64(envName string, defaultValue int64) int64
- func Int8(envName string, defaultValue int8) int8
- func Is(envName, value string) bool
- func Load()
- func Path() []string
- func Set(name, value string) error
- func Str(name string, optionalDefault ...string) string
- func StrAlt(name1, name2 string, optionalDefault ...string) string
- func UInt16(envName string, defaultValue uint16) uint16
- func UInt32(envName string, defaultValue uint32) uint32
- func UInt64(envName string, defaultValue uint64) uint64
- func UInt8(envName string, defaultValue uint8) uint8
- func Unload()
- func Unset(name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsBool ¶
AsBool can be used to interpret a string value as either true or false. Examples of true values are "yes" and "1".
func Bool ¶
Bool returns the bool value of the given environment variable name. Returns false if it is not declared or empty.
func Contains ¶ added in v1.5.0
Contains checks if the given environment variable contains the given string
func DurationHours ¶ added in v1.4.0
DurationHours interprets the environment variable value as hours and returns a time.Duration. The given default number is interpreted as the number of hours.
func DurationMinutes ¶ added in v1.4.0
DurationMinutes interprets the environment variable value as minutes and returns a time.Duration. The given default number is interpreted as the number of minutes.
func DurationSeconds ¶ added in v1.3.0
DurationSeconds interprets the environment variable value as seconds and returns a time.Duration. The given default number is interpreted as the number of seconds.
func ExpandUser ¶ added in v1.6.0
ExpandUser replaces a leading ~ or $HOME with the path to the home directory of the current user
func File ¶ added in v1.7.0
File does the same as Str, but expands a leading "~" or "$HOME" string to the home directory of the current user.
func Float32 ¶ added in v1.9.1
Float32 returns the number stored in the environment variable, or the provided default value.
func Float64 ¶ added in v1.2.0
Float64 returns the number stored in the environment variable, or the provided default value.
func HomeDir ¶ added in v1.6.0
func HomeDir() string
HomeDir returns the path to the home directory of the user, if available. If not available, $LOGNAME or $USER are used to construct a path starting with /home/. If $LOGNAME and $USER are not available, just "/tmp" is returned. The returned string is what the home directory should have been named, if it would have existed. No checks are made for if the directory exists.
func Int ¶
Int returns the number stored in the environment variable, or the provided default value.
func Int16 ¶ added in v1.9.1
Int16 returns the number stored in the environment variable, or the provided default value.
func Int32 ¶ added in v1.9.1
Int32 returns the number stored in the environment variable, or the provided default value.
func Int64 ¶ added in v1.2.0
Int64 returns the number stored in the environment variable, or the provided default value.
func Int8 ¶ added in v1.9.1
Int8 returns the number stored in the environment variable, or the provided default value.
func Is ¶ added in v1.5.0
Is returns true if the given environment variable is the given string value. The whitespace of both values are trimmed before the comparison.
func Load ¶ added in v1.9.0
func Load()
Load reads all environment variables into the environment map. It also instructs env to use the cache. If a program uses os.Setenv, then Load() should be called after that, in order to read the new values. This function can be used both as an "init and enable cache" function and as a "reload" function.
func Path ¶ added in v1.7.0
func Path() []string
Path returns the elements in the $PATH environment variable
func Set ¶ added in v1.9.0
Set calls os.Setenv. If caching is enabled, the value in the environment map is also set and there is no need to call Load() to re-read the environment variables from the system.
func Str ¶
Str does the same as os.Getenv, but allows the user to provide a default value (optional). Only the first optional argument is used, the rest is discarded.
func StrAlt ¶ added in v1.6.0
StrAlt will return the string value of the first given environment variable name, or, if that is not available, use the string value of the second given environment variable. If none are available, the optional default string is returned.
func UInt16 ¶ added in v1.9.1
UInt16 returns the number stored in the environment variable, or the provided default value.
func UInt32 ¶ added in v1.9.1
UInt32 returns the number stored in the environment variable, or the provided default value.
func UInt64 ¶ added in v1.9.1
UInt64 returns the number stored in the environment variable, or the provided default value.
func UInt8 ¶ added in v1.9.1
UInt8 returns the number stored in the environment variable, or the provided default value.
Types ¶
This section is empty.