Documentation ¶
Overview ¶
Package env provides a collection of environment variable utilities
Index ¶
- func AppendPATH(path string) (err error)
- 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 PATH() (path string)
- func PATHS() (paths []string)
- func PrependPATH(path string) (err error)
- func PrunePATH(path string) (err error)
- func Set(key, value string)
- func String(key string, def string) (value string)
- func TidyPATH() (err error)
- type Env
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendPATH ¶ added in v1.1.0
AppendPATH moves or adds the given path to the end of the PATH environment variable
func PATHS ¶ added in v1.1.0
func PATHS() (paths []string)
PATHS returns a slice of paths from the current PATH environment
func PrependPATH ¶ added in v1.1.0
PrependPATH moves or adds the given path to the start of the PATH environment variable
func PrunePATH ¶ added in v1.1.0
PrunePATH removes the given path from the PATH environment variable
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) // Include applies all variables within the others to this Env instance. // Note that keys are not deleted and any existing keys are clobbered by // the others, in the order the others are given Include(others ...Env) // WriteEnvDir makes the given directory path if it doesn't exist already // and then for each key/value pair in the Env, creates a file named with // the key and the value as the contents WriteEnvDir(path string) (err error) // 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.