Documentation
¶
Overview ¶
Package env provides a collection of environment variable utilities
Index ¶
- func Bool(key string, def bool) (state bool)
- func Clear()
- func Environ() (variables []string)
- func Expand(input string) (expanded string)
- func Export() (err error)
- func Float(key string, def float64) (decimal float64)
- func Get(key string) (value string, present bool)
- func Import(environment []string)
- func Int(key string, def int) (number int)
- func Len() (count int)
- func Set(key, value string)
- func String(key string, def string) (value string)
- type Env
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Env ¶
type Env interface {
// Len returns the number of variables present
Len() (count int)
// Clear deletes all Env variables
Clear()
// Environ returns a copy of all the underlying keys and values in the
// form of "key=value"
Environ() (variables []string)
// Clone returns a complete duplicate of the current Env, changes to
// a clone do not have any effect upon the original Env
Clone() (clone Env)
// Export updates the actual os environment, calling os.Setenv for each
// variable present. Export stops at the first error
Export() (err error)
// Import updates the Env instance with the given `environment`
// variables, in the form of "key=value". Inputs missing the equal sign are
// ignored and all values have any quotes trimmed. Quotations are detected
// when the first and last characters are the same and are one of the
// following: backtick (&96;), quote (') or double quote (")
Import(environment []string)
// Expand replaces all `$key` and `${key}` references in the `input` string
// with their corresponding `key` values. Any references not present within
// the Env are replaced with empty strings
Expand(input string) (expanded string)
// Get looks for the variable `key` and if `present` returns the exact
// `value`
Get(key string) (value string, present bool)
// Set updates the Env `key` with the given `value`
Set(key, value string)
// Unset removes the `key` from the Env
Unset(key string)
// Bool transforms the value associated with `key` into a boolean state. If
// the value is not a detectable state, `def` is returned. Detection is
// handled by the github.com/go-corelibs/strings package IsTrue and IsFalse
// functions
Bool(key string, def bool) (state bool)
// Int uses strconv.Atoi to transform the value associated with `key` and
// if not present or strconv.Atoi encountered an error, returns `def`
Int(key string, def int) (number int)
// Float uses strconv.ParseFloat to transform the value associated with
// `key` and if not present or strconv.ParseFloat encountered an error,
// returns `def`
Float(key string, def float64) (decimal float64)
// String uses strings.TrimSpace to transform the value associated with
// `key` and if not present, returns `def`
String(key string, def string) (value string)
}
Env is an abstraction around the standard os package env related things with some conveniences added like Env.Int and Env.Float
Click to show internal directories.
Click to hide internal directories.