Documentation ¶
Index ¶
- type Env
- func (env *Env) GetBool(dfault bool, v ...string) bool
- func (env *Env) GetDuration(dfault time.Duration, v ...string) time.Duration
- func (env *Env) GetFloat(dfault float64, v ...string) float64
- func (env *Env) GetInt(dfault int, v ...string) int
- func (env *Env) GetTime(layout string, dfault time.Time, v ...string) time.Time
- func (env *Env) Getenv(dfault string, v ...string) string
- func (env *Env) Load() error
- func (env *Env) Read() (map[string]string, error)
- func (env *Env) SetPrefix(prefix string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Env ¶
type Env struct {
Prefix string
}
func NewEnvWithPrefix ¶
NewEnvWithPrefix returns a pointer to a new Env with the prefix set to `prefix`.
func (*Env) GetBool ¶
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 ¶
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 ¶
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 ¶
GetInt returns the value of the first valid environment variable as an integer, or the default provided value.
func (*Env) GetTime ¶
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 ¶
Getenv returns the value of first valid environment variable, or the default provided value.
func (*Env) Load ¶
Load a .env configuration file if it exists, and add its configuration to the environment.