Documentation ¶
Overview ¶
Package env provides functionality to dynamically load the environment variables
Note: This is just a modified copy and wrapper around the gotenv package by suboisto
Index ¶
- Variables
- func Apply(r io.Reader) error
- func Environ() []string
- func Expand(v string, env Env) (string, error)
- func ExpandAll(v interface{}, env Env) error
- func Getenv(key string) string
- func Load(filenames ...string) error
- func LoadFiles(files ...string)
- func LookupEnv(key string) (string, bool)
- func Must(fn func(filenames ...string) error, filenames ...string)
- func OverApply(r io.Reader) error
- func OverLoad(filenames ...string) error
- type Env
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownVariable = fmt.Errorf("unknown variable") ErrCyclicVariable = fmt.Errorf("cyclic variable") )
var Files = []string{"ntt.env", "k3.env"}
Functions ¶
func Apply ¶ added in v0.16.2
Apply is a function to load an io Reader then export the valid variables into environment variables if they do not exist.
func Environ ¶ added in v0.16.2
func Environ() []string
Environ returns the current process's environment as a string-slice of the form key=value. It also replaces K3-prefixes with NTT-prefixes.
func Getenv ¶
Lookup key in process environment. Is key begins with "NTT_" also lookup key with "K3_" prefix.
func Load ¶
Load is a function to load a file or multiple files and then export the valid variables into environment variables if they do not exist. When it's called with no argument, it will load `.env` file on the current path and set the environment variables. Otherwise, it will loop over the filenames parameter and set the proper environment variables.
func LoadFiles ¶ added in v0.16.2
func LoadFiles(files ...string)
LoadFiles environment files ntt.env and k3.env
func Must ¶ added in v0.16.2
Must is wrapper function that will panic when supplied function returns an error.
Types ¶
type Env ¶
Env holds key/value pair of valid environment variable
func EnvironMap ¶ added in v0.16.2
func EnvironMap() Env
EnvironMap returns the current process's environment as a string-map. It also replaces K3-prefixes with NTT-prefixes.
func Parse ¶
Parse is a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables. It expands the value of a variable from the environment variable but does not set the value to the environment itself. This function is skipping any invalid lines and only processing the valid one.
func ParseFiles ¶ added in v0.16.2
ParseFiles environment files ntt.env and k3.env
func StrictParse ¶ added in v0.16.2
StrictParse is a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables. It expands the value of a variable from the environment variable but does not set the value to the environment itself. This function is returning an error if there are any invalid lines.