Documentation ¶
Overview ¶
Package env can retrieve and parse environment variables, with defaults.
Index ¶
- func Bool(key string, fallback bool) bool
- func BoolVar(p *bool, key string, fallback bool)
- func Duration(key string, fallback time.Duration) time.Duration
- func DurationVar(p *time.Duration, key string, fallback time.Duration)
- func Float32(key string, fallback float32) float32
- func Float32Var(p *float32, key string, fallback float32)
- func Float64(key string, fallback float64) float64
- func Float64Var(p *float64, key string, fallback float64)
- func Int(key string, fallback int) int
- func Int64(key string, fallback int64) int64
- func Int64Var(p *int64, key string, fallback int64)
- func IntVar(p *int, key string, fallback int)
- func Lookup(key string) (string, bool)
- func Prefix() string
- func SetPrefix(prefix string)
- func String(key string, fallback string) string
- func StringVar(p *string, key string, fallback string)
- func Uint(key string, fallback uint) uint
- func Uint64(key string, fallback uint64) uint64
- func Uint64Var(p *uint64, key string, fallback uint64)
- func UintVar(p *uint, key string, fallback uint)
- type VarSet
- func (vs *VarSet) Bool(key string, fallback bool) bool
- func (vs *VarSet) Duration(key string, fallback time.Duration) time.Duration
- func (vs *VarSet) Float32(key string, fallback float32) float32
- func (vs *VarSet) Float64(key string, fallback float64) float64
- func (vs *VarSet) Int(key string, fallback int) int
- func (vs *VarSet) Int64(key string, fallback int64) int64
- func (vs *VarSet) Lookup(key string) (string, bool)
- func (vs *VarSet) Prefix() string
- func (vs *VarSet) SetPrefix(prefix string)
- func (vs *VarSet) String(key string, fallback string) string
- func (vs *VarSet) Uint(key string, fallback uint) uint
- func (vs *VarSet) Uint64(key string, fallback uint64) uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bool ¶
Bool retrieves the value of the environment variable named by the key, parses the value as a boolean, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func BoolVar ¶
BoolVar retrieves the value of the environment variable named by the key, parses the value as a boolean, and stores the result into the variable pointed by p.
func Duration ¶
Duration retrieves the value of the environment variable named by the key, parses the value as time.Duration, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func DurationVar ¶
DurationVar retrieves the value of the environment variable named by the key, parses the value as time.Duration, and stores the result into the variable pointed by p.
func Float32 ¶
Float32 retrieves the value of the environment variable named by the key, parses the value as a floating-point number, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func Float32Var ¶
Float32Var retrieves the value of the environment variable named by the key, parses the value as a floating-point number, and stores the result into the variable pointed by p.
func Float64 ¶
Float64 retrieves the value of the environment variable named by the key, parses the value as a 64-bit floating-point number, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func Float64Var ¶
Float64Var retrieves the value of the environment variable named by the key, parses the value as a 64-bit floating-point number, and stores the result into the variable pointed by p.
func Int ¶
Int retrieves the value of the environment variable named by the key, parses the value as an integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func Int64 ¶
Int64 retrieves the value of the environment variable named by the key, parses the value as a 64-bit integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func Int64Var ¶
Int64Var retrieves the value of the environment variable named by the key, parses the value as a 64-bit integer, and stores the result into the variable pointed by p.
func IntVar ¶
IntVar retrieves the value of the environment variable named by the key, parses the value as an integer, and stores the result into the variable pointed by p.
func Lookup ¶
Lookup retrieves the value of the environment variable named by the key. If the variable is present in the environment the value is returned and the boolean is true. Otherwise, the returned value will be empty and the boolean will be false.
func SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix makes this VarSet prepend the value of prefix to every key before it looks it up in the environment using String, StringVar, Bool, Int, et al. Use the empty string to reset.
func String ¶
String retrieves the value of the environment variable named by the key. If the variable is present in the environment, its value (which may be empty) is returned, otherwise fallback is returned.
func StringVar ¶
StringVar retrieves the value of the environment variable named by the key, and stores the result into the variable pointed by p.
func Uint ¶
Uint retrieves the value of the environment variable named by the key, parses the value as an unsigned integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func Uint64 ¶
Uint64 retrieves the value of the environment variable named by the key, parses the value as an unsigned 64-bit integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
Types ¶
type VarSet ¶
type VarSet struct {
// contains filtered or unexported fields
}
VarSet represents a set of environment variables managed as key-value pairs.
func (*VarSet) Bool ¶
Bool retrieves the value of the environment variable named by the key, parses the value as a boolean, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func (*VarSet) Duration ¶
Duration retrieves the value of the environment variable named by the key, parses the value as time.Duration, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func (*VarSet) Float32 ¶
Float32 retrieves the value of the environment variable named by the key, parses the value as a floating-point number, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func (*VarSet) Float64 ¶
Float64 retrieves the value of the environment variable named by the key, parses the value as a 64-bit floating-point number, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func (*VarSet) Int ¶
Int retrieves the value of the environment variable named by the key, parses the value as an integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func (*VarSet) Int64 ¶
Int64 retrieves the value of the environment variable named by the key, parses the value as a 64-bit integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.
func (*VarSet) Lookup ¶
Lookup retrieves the value of the environment variable named by the key. If the variable is present in the environment the value is returned and the boolean is true. Otherwise, the returned value will be empty and the boolean will be false.
func (*VarSet) SetPrefix ¶
SetPrefix makes this VarSet prepend the value of prefix to every key before it looks it up in the environment using String, StringVar, Bool, Int, et al. Use the empty string to reset.
func (*VarSet) String ¶
String retrieves the value of the environment variable named by the key. If the variable is present in the environment, its value (which may be empty) is returned, otherwise fallback is returned.
func (*VarSet) Uint ¶
Uint retrieves the value of the environment variable named by the key, parses the value as an unsigned integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.