env

package
v1.0.579-098229d Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package env provides a few helpers to load in environment variables with defaults

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

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

func NewLoader

func NewLoader() *Loader

func (*Loader) Bool

func (l *Loader) Bool(fld *bool, env string)

Bool inspects the system env var given by env. If it is present it will use the truthy or falsy strings as per ParseBool to set the contents of fld. If the parse fails the content of fld is left unaltered and the loader multi error added to.

func (*Loader) ChangeDefault

func (l *Loader) ChangeDefault(env, def string)

func (*Loader) Duration

func (l *Loader) Duration(fld *time.Duration, env string)

Duration inspects the system env var given by env. If it is present it will parse the value as a time.Duration as per time.ParseDuration to set the contents of fld. If the parse fails the content of fld is left unaltered and the loader multi error added to.

func (*Loader) Err

func (l *Loader) Err() error

func (*Loader) Int

func (l *Loader) Int(fld *int, env string)

Int inspects the system env var given by env. If it is present it will parse the value as an int as per Atoi to set the contents of fld. If the parse fails the content of fld is left unaltered and the loader multi error added to.

func (*Loader) SecretFromFile

func (l *Loader) SecretFromFile(fld *secret.String, env string)

SecretFromFile loads in the content of the file given in the env var. A slight potential trap is that the default value provided would be the content of the file and not the file path. If the env var is not set or is set but is empty then the default value is left unaltered and the loader multi error added to.

func (*Loader) String

func (l *Loader) String(fld *string, env string)

String inspects the system env var given by env. If it is present it will set the contents of fld.

func (*Loader) VarsUsed

func (l *Loader) VarsUsed() Vars

type Var

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

func (Var) Name

func (f Var) Name() string

func (Var) String

func (f Var) String() string

type Vars

type Vars []Var

func (Vars) Sort

func (v Vars) Sort()

Sort the vars v in place alphabetically

func (*Vars) SortUnique

func (v *Vars) SortUnique()

SortUnique makes sure the names of the Vars in v are unique removing duplicates and sorts the resulting vars v in place alphabetically. The receiver v may shrink as a result.

Jump to

Keyboard shortcuts

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