env

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2016 License: BSD-2-Clause, MIT Imports: 5 Imported by: 0

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

View Source
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

func (e *Env) ExpandEnv(s string) string

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

func (e *Env) GetEnv(key string) string

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.

func (*Env) LookupEnv

func (e *Env) LookupEnv(key string) (string, bool)

LookupEnv retrieves the value of the environment variable named by the key. If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL