Documentation ¶
Overview ¶
Package environ is a simple environment variable manipulation library. It couples the system's environment, representated as a []string of KEY[=VALUE] strings, into a key/value map and back.
Index ¶
- func Join(k, v string) string
- func Split(v string) (key, value string)
- func SystemIsCaseInsensitive() bool
- type Env
- func (e Env) Clone() Env
- func (e Env) Get(k string) (v string, ok bool)
- func (e Env) GetEmpty(k string) string
- func (e Env) Iter(cb func(k, v string) bool)
- func (e Env) Len() int
- func (e *Env) Load(m map[string]string)
- func (e *Env) LoadSlice(s []string)
- func (e Env) Map() map[string]string
- func (e *Env) Remove(k string) bool
- func (e *Env) RemoveMatch(fn func(k, v string) bool)
- func (e *Env) Set(k, v string)
- func (e *Env) SetEntry(entry string)
- func (e Env) Sorted() []string
- func (e Env) String() string
- func (e *Env) Update(other Env)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Split ¶
Split splits the supplied environment variable value into a key/value pair.
If v is of the form:
- KEY, returns (KEY, "")
- KEY=, returns (KEY, "")
- KEY=VALUE, returns (KEY, VALUE)
func SystemIsCaseInsensitive ¶
func SystemIsCaseInsensitive() bool
SystemIsCaseInsensitive returns true if the local operating system treats environment variable keys in a case-insensitive manner.
Types ¶
type Env ¶
type Env struct { // CaseInsensitive is true if environment keys are case-insensitive. CaseInsensitive bool // contains filtered or unexported fields }
Env contains system environment variables. It preserves each environment variable verbatim (even if invalid).
func New ¶
New instantiates a new Env instance from the supplied set of environment KEY=VALUE strings using LoadSlice.
The environment is automatically configured with the local system's case insensitivity.
func System ¶
func System() Env
System returns an Env instance instantiated with the current os.Environ values.
The environment is automatically configured with the local system's case insensitivity.
func (Env) Get ¶
Get returns the environment value for the supplied key.
If the value is defined, ok will be true and v will be set to its value (note that this can be empty if the environment has an empty value). If the value is not defined, ok will be false.
func (Env) GetEmpty ¶
GetEmpty is the same as Get, except that instead of returning a separate boolean indicating the presence of a key, it will return an empty string if the key is missing.
func (Env) Iter ¶
Iter iterates through all of the key/value pairs in Env and invokes the supplied callback, cb, for each element.
If the callback returns false, iteration will stop immediately.
func (*Env) Load ¶
Load adds environment variables defined in a key/value map to an existing environment.
func (*Env) LoadSlice ¶
LoadSlice adds environment variable entries, specified as "KEY[=VALUE]" strings, into an existing environment.
Entries are added in order. If there are duplicates, later entries will override earlier ones.
func (Env) Map ¶
Map returns a map of the key/value values in the environment.
This is a clone of the contents of e; manipulating this map will not change the values in e.
func (*Env) Remove ¶
Remove removes a value from the environment, returning true if the value was present. If the value was missing, Remove returns false.
Remove is different from Set(k, "") in that Set persists the key with an empty value, while Remove removes it entirely.
func (*Env) RemoveMatch ¶
RemoveMatch iterates over all keys and values in the environment, invoking the callback function, fn, for each key/value pair. If fn returns true, the key is removed from the environment.
func (*Env) Update ¶
Update adds all key/value from other to the current environment. If there is a duplicate key, the value from other will overwrite the value from e.
Values from other will be sorted and added in alphabetic order. This means that if e is case insensitive and there are multiple keys in other that converge on the same case insensitive key, the one that is alphabetically highest will be added.