env

package
v0.0.0-...-95ed4ff Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TagNameEnvironmentVariableName is the struct tag for what environment variable to use to populate a field.
	TagNameEnvironmentVariableName = "env"
	// FlagCSV is a field tag flag (say that 10 times fast).
	FlagCSV = "csv"
	// FlagBase64 is a field tag flag (say that 10 times fast).
	FlagBase64 = "base64"
	// FlagBytes is a field tag flag (say that 10 times fast).
	FlagBytes = "bytes"
)

Variables

This section is empty.

Functions

func Restore

func Restore()

Restore sets .Env() to the current os environment.

func SetEnv

func SetEnv(vars Vars)

SetEnv sets the env vars.

Types

type Marshaler

type Marshaler interface {
	MarshalEnv(vars Vars) error
}

Marshaler is a type that implements `ReadInto`.

type Vars

type Vars map[string]string

Vars is a set of environment variables.

func Env

func Env() Vars

Env returns the current env var set.

func NewVars

func NewVars() Vars

NewVars returns a new env var set.

func NewVarsFromEnvironment

func NewVarsFromEnvironment() Vars

NewVarsFromEnvironment reads an EnvVar set from the environment.

func (Vars) Base64

func (ev Vars) Base64(envVar string, defaults ...[]byte) ([]byte, error)

Base64 returns a []byte value for a given key whose value is encoded in base64.

func (Vars) Bool

func (ev Vars) Bool(envVar string, defaults ...bool) bool

Bool returns a boolean value for a key, defaulting to false. Valid "truthy" values are `true`, `yes`, and `1`. Everything else is false, including `REEEEEEEEEEEEEEE`.

func (Vars) Bytes

func (ev Vars) Bytes(envVar string, defaults ...[]byte) []byte

Bytes returns a []byte value for a given key.

func (Vars) CSV

func (ev Vars) CSV(envVar string, defaults ...string) []string

CSV returns a string array for a given string var.

func (Vars) Delete

func (ev Vars) Delete(key string)

Delete removes a key from the set.

func (Vars) Duration

func (ev Vars) Duration(envVar string, defaults ...time.Duration) (time.Duration, error)

Duration returns a duration value for a given key.

func (Vars) Float64

func (ev Vars) Float64(envVar string, defaults ...float64) (float64, error)

Float64 returns an float64 value for a given key.

func (Vars) Has

func (ev Vars) Has(envVar string) bool

Has returns if a key is present in the set.

func (Vars) HasAll

func (ev Vars) HasAll(envVars ...string) bool

HasAll returns if all of the given vars are present in the set.

func (Vars) HasAny

func (ev Vars) HasAny(envVars ...string) bool

HasAny returns if any of the given vars are present in the set.

func (Vars) Int

func (ev Vars) Int(envVar string, defaults ...int) (int, error)

Int returns an integer value for a given key.

func (Vars) Int32

func (ev Vars) Int32(envVar string, defaults ...int32) (int32, error)

Int32 returns an integer value for a given key.

func (Vars) Int64

func (ev Vars) Int64(envVar string, defaults ...int64) (int64, error)

Int64 returns an int64 value for a given key.

func (Vars) Must

func (ev Vars) Must(keys ...string)

Must enforces that a given set of environment variables are present and panics if they're not present.

func (Vars) MustBase64

func (ev Vars) MustBase64(envVar string, defaults ...[]byte) []byte

MustBase64 returns a []byte value for a given key encoded with base64, and panics if malformed.

func (Vars) MustDuration

func (ev Vars) MustDuration(envVar string, defaults ...time.Duration) time.Duration

MustDuration returnss a duration value for a given key and panics if malformed.

func (Vars) MustFloat64

func (ev Vars) MustFloat64(envVar string, defaults ...float64) float64

MustFloat64 returns an float64 value for a given key and panics if it is malformed.

func (Vars) MustInt

func (ev Vars) MustInt(envVar string, defaults ...int) int

MustInt returns an integer value for a given key and panics if it is malformed.

func (Vars) MustInt32

func (ev Vars) MustInt32(envVar string, defaults ...int32) int32

MustInt32 returns an integer value for a given key and panics if it is malformed.

func (Vars) MustInt64

func (ev Vars) MustInt64(envVar string, defaults ...int64) int64

MustInt64 returns an int64 value for a given key and panics if it is malformed.

func (Vars) MustUint32

func (ev Vars) MustUint32(envVar string, defaults ...uint32) uint32

MustUint32 returns an uint32 value for a given key and panics if it is malformed.

func (Vars) MustUint64

func (ev Vars) MustUint64(envVar string, defaults ...uint64) uint64

MustUint64 returns an uint64 value for a given key and panics if it is malformed.

func (Vars) Raw

func (ev Vars) Raw() []string

Raw returns a raw KEY=VALUE form of the vars.

func (Vars) ReadFile

func (ev Vars) ReadFile(path string) error

ReadFile reads a file from the env.

func (Vars) ReadInto

func (ev Vars) ReadInto(obj interface{}) error

ReadInto reads the environment into tagged fields on the `obj`.

func (Vars) Require

func (ev Vars) Require(keys ...string) error

Require enforces that a given set of environment variables are present.

func (Vars) Restore

func (ev Vars) Restore(key string)

Restore resets an environment variable to it's environment value.

func (Vars) Set

func (ev Vars) Set(envVar, value string)

Set sets a value for a key.

func (Vars) String

func (ev Vars) String(envVar string, defaults ...string) string

String returns a string value for a given key, with an optional default vaule.

func (Vars) Uint32

func (ev Vars) Uint32(envVar string, defaults ...uint32) (uint32, error)

Uint32 returns an uint32 value for a given key.

func (Vars) Uint64

func (ev Vars) Uint64(envVar string, defaults ...uint64) (uint64, error)

Uint64 returns an uint64 value for a given key.

func (Vars) Union

func (ev Vars) Union(other Vars) Vars

Union returns the union of the two sets, other replacing conflicts.

func (Vars) Vars

func (ev Vars) Vars() []string

Vars returns all the vars stored in the env var set.

Jump to

Keyboard shortcuts

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