Documentation
¶
Overview ¶
Package env provides simple environment primitives.
An environment holds the boundary for standard and logging I/O, process environment, and arguments.
Be aware that environment variables are immutable, as opposed to os.env which uses syscall.
Example:
func main() {
Main(env.Default)
}
func Main(e env.Env) {
e.Flags.Parse()
e.Log.Println("parsed flags")
h := e.Envvars["HOME"]
e.Log.Println(h)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Default = &Env{ In: os.Stdin, Out: os.Stdout, Err: os.Stderr, Envvars: map[string]string{}, Flags: flag.CommandLine, Log: log.New(os.Stderr, "", log.LstdFlags), }
Default represents a set of expected presents for an environment.
Functions ¶
This section is empty.
Types ¶
type Env ¶
type Env struct {
In io.Reader
Out io.Writer
Err io.Writer
Envvars map[string]string
Flags *flag.FlagSet
Log *log.Logger
}
An Env holds the command line and other values which can be injected into a program.
func (*Env) ExpandEnv ¶
ExpandEnv replaces ${var} or $var in the string according to the values of the current environment variables. References to undefined variables are replaced by the empty string.
func (*Env) GetEnv ¶
GetEnv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present.