env

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package env contains abstractions to work with environment variables, such as Variable and Environment. It also includes functions for better integration with the built-in os package.

Index

Constants

View Source
const (
	Go111Module = "GO111MODULE"
	GoArch      = "GOARCH"
	GoDebug     = "GODEBUG"
	GoGC        = "GOGC"
	GoMaxProcs  = "GOMAXPROCS"
	GoOS        = "GOOS"
	GoPath      = "GOPATH"
	GoRace      = "GORACE"
	GoRoot      = "GOROOT"
	GoTraceback = "GOTRACEBACK"
)

Environment variables relate to the built-in runtime package. See https://pkg.go.dev/runtime/#hdr-Environment_Variables.

Variables

This section is empty.

Functions

This section is empty.

Types

type Environment

type Environment []Variable

Environment represents a set of environment variables.

func From

func From(environ []string) Environment

From converts an environment in the form "key=value" into Environment. It skips invalid entries silently.

See the example.

func (Environment) Environ

func (env Environment) Environ() []string

Environ returns a copy of strings representing the environment, in the form "key=value".

func (Environment) Lookup

func (env Environment) Lookup(key string) (Variable, bool)

Lookup 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.

type Variable

type Variable struct {
	// contains filtered or unexported fields
}

Variable represents an environment variable.

func Must

func Must(key, value string) Variable

Must does the same as the New but throws panic if something went wrong.

func New

func New(key, value string) (Variable, error)

New returns a new Variable on top of the passed key/value pair. It returns error if something went wrong.

func (Variable) Name

func (v Variable) Name() string

Name returns an environment variable name.

func (Variable) String

func (v Variable) String() string

String returns a string representation of an environment variable in the form "key=value".

func (Variable) Value

func (v Variable) Value() string

Value returns an environment variable value.

Jump to

Keyboard shortcuts

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