Documentation ¶
Index ¶
- func IsVarNotFound(err error) bool
- func IsVarNotParsable(err error) bool
- func NewVarNotFoundErr(name string) error
- func NewVarNotParsableErr(name string) error
- func NoopLookup(name string) (string, bool)
- type Lookup
- type VarSet
- func (v *VarSet) AppendSource(s Lookup) *VarSet
- func (v *VarSet) Bool(name string) (bool, error)
- func (v *VarSet) IsSet(name string) bool
- func (v *VarSet) Lookup(name string) (string, bool)
- func (v *VarSet) MustBool(name string) bool
- func (v *VarSet) MustHexEncodedByteArray(name string, decodedByteLength int) []byte
- func (v *VarSet) MustString(name string) string
- func (v *VarSet) String(name, defaultVal string) string
- type VarSetOpt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsVarNotFound ¶
IsVarNotFound returns a boolean indicating whether the error is known to report that an environment variable is not found.
func IsVarNotParsable ¶
IsVarNotParsable returns a boolean indicating whether the error is known to report that an environment variable is not parsable.
func NewVarNotFoundErr ¶
NewVarNotFoundErr makes a new error that indicates that an environment variable is not found.
func NewVarNotParsableErr ¶
NewVarNotParsableErr makes a new error that indicates that an environment variable is not parsable.
func NoopLookup ¶
NoopLookup always returns false for the environment variable with the given name. Useful as a fallback to return for an env lookup that may not always be applicable, e.g. if not running in CloudFoundry, a user provided service lookup won't be applicable.
Types ¶
type Lookup ¶
Lookup must return the value for the environment variable with the given name and whether or not it was found.
type VarSet ¶
type VarSet struct {
// contains filtered or unexported fields
}
VarSet provides methods to access environment variables from a list of Lookup sources.
func (*VarSet) AppendSource ¶
AppendSource adds s as another lookup source after all existing sources.
func (*VarSet) Bool ¶
Bool gets the boolean environment variable with the given name, if set. If not found, returns false. If found and cannot parse, returns an error.
func (*VarSet) IsSet ¶
IsSet looks for a given name within all lookup sources in order. If found, true is returned, else false.
func (*VarSet) Lookup ¶
Lookup looks for a given name within all lookup sources in order. If no variable is found, an empty string and false is returned.
func (*VarSet) MustBool ¶
MustBool gets the boolean environment variable with the given name, if set. If not set, false is returned. This matches behavior one would often see with command line boolean arguments: if you don't set it, it defaults to false. It will panic with an error if it is not a valid boolean. If desired, callers can use IsVarNotParsable when recovering from the panic in order to check type of the error.
func (*VarSet) MustHexEncodedByteArray ¶
MustHexEncodedByteArray gets the hex-encoded environment variable with the given name, if set. It will panic with an error if it is not set if it is not a valid hex-encoded string or if its length does not match decodedByteLength. If desired, callers can use IsVarNotFound and IsVarNotParsable when recovering from the panic in order to check type of the error.
func (*VarSet) MustString ¶
MustString gets the string environment variable with the given name, if set. It will panic with an error if it is not set. If desired, callers can use IsVarNotFound when recovering from the panic in order to check type of the error.
type VarSetOpt ¶
type VarSetOpt func(v *VarSet)
VarSetOpt is a type which defines VarSet options.
func WithMapLookup ¶
WithMapLookup configures the VarSet to use the given map as a lookup source.
func WithOSLookup ¶
func WithOSLookup() VarSetOpt
WithOSLookup configures the VarSet to use the OS env as a lookup source.