staticenv

package module
v0.0.0-...-80f816c Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2019 License: MIT Imports: 7 Imported by: 0

README

staticenv

A package for reading environment variables into statically typed variables.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env struct {
	Prefix string
}

func NewEnv

func NewEnv() *Env

NewEnv returns a pointer to a new Env.

func NewEnvWithPrefix

func NewEnvWithPrefix(prefix string) *Env

NewEnvWithPrefix returns a pointer to a new Env with the prefix set to `prefix`.

func (*Env) GetBool

func (env *Env) GetBool(dfault bool, v ...string) bool

GetBool returns the value of the first valid environment variable as a bool, or it will return the provided default value. It accepts 1, t, T, TRUE, true, True, 0, f, F, False, false, False. If any other value is found, it will return the provided default value.

func (*Env) GetDuration

func (env *Env) GetDuration(dfault time.Duration, v ...string) time.Duration

GetDuration returns the value of the first valid environment variable as a time.Duration, or it will return the provided default value.

A duration is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".

func (*Env) GetFloat

func (env *Env) GetFloat(dfault float64, v ...string) float64

GetFloat returns the value of the first valid environment variable as a 64 bit float, or the default provided value.

If the value is well-formed and near a valid floating point number, it will return the nearest floating point number rounded using IEEE754 unbiased rounding.

If the value is not syntactically well-formed, it will return the provided default value.

If the value is well-formed but is more than 1/2 ULP away from the largest 64 bit floating point number, it will return the provided default value.

func (*Env) GetInt

func (env *Env) GetInt(dfault int, v ...string) int

GetInt returns the value of the first valid environment variable as an integer, or the default provided value.

func (*Env) GetTime

func (env *Env) GetTime(layout string, dfault time.Time, v ...string) time.Time

GetTime returns the value of the first environment variable as a time.Time, or it will return the provided default value. It also takes a layout string to parse the time.Time. See https://golang.org/pkg/time/#Parse for more information about the layout's format.

func (*Env) Getenv

func (env *Env) Getenv(dfault string, v ...string) string

Getenv returns the value of first valid environment variable, or the default provided value.

func (*Env) Load

func (env *Env) Load() error

Load a .env configuration file if it exists, and add its configuration to the environment.

func (*Env) Read

func (env *Env) Read() (map[string]string, error)

Read a .env configuration file if it exists, and return the configuration as a map[string]string.

func (*Env) SetPrefix

func (env *Env) SetPrefix(prefix string)

SetPrefix sets the prefix for the environment.

Jump to

Keyboard shortcuts

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