Documentation
¶
Index ¶
- func Parse(environment Environment, schema Schema) error
- func ParseFile(path string, schema Schema) error
- func ParseMap(m map[string]string, schema Schema) error
- func ParseOS(schema Schema) error
- type Environment
- type Parser
- func Bool(b *bool, required bool) Parser
- func BoolOr(b *bool, alt bool) Parser
- func Float(f *float64, required bool) Parser
- func FloatOr(f *float64, alt float64) Parser
- func Int(i *int, required bool) Parser
- func IntOr(i *int, alt int) Parser
- func Secret(s **conceal.Text, required bool) Parser
- func String(s *string, required bool) Parser
- func StringOr(s *string, alt string) Parser
- type Schema
- type Variable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
func Parse(environment Environment, schema Schema) error
Parse uses the given Schema to parse the environment variables in the given Environment. If the values of environment variables in Environment do not match the schema, or required variables are missing, an error is returned.
func ParseFile ¶ added in v0.3.5
ParseFile is a convenience function for parsing the given Schema of environment variables using the given .env file path. The contents of the file are read and interpreted as key=value pairs, one per line. If the environment variable contents of the file do not match the schema, or required variables are missing, an error is returned.
func ParseMap ¶ added in v0.3.6
ParseMap is a convenience function for parsing the given Schema of environment variables using the given map. The contents of the map are inferred as key=value pairs. If the contents of the map do not match the schema, or required variables are missing, an error is returned.
func ParseOS ¶
ParseOS is a convenience function for parsing the given Schema of environment variables using the environment variables accessed by the standard libraray os package. If the values of environment variables do not match the schema, or required variables are missing, an error is returned.
Types ¶
type Environment ¶
Environment is something that implements Getenv().
Most use cases can simply make use of the OS implementation which is backed by the standard library os package.
var OS Environment = new(osEnv)
OS is an implementation of Environment that uses the standard library os package to retrieve actual environment variables.
func File ¶ added in v0.3.3
func File(filename string) Environment
File is an implementation of Environment that reads environment variables from a file.
e.g. /etc/os-release
func Map ¶ added in v0.3.6
func Map(m map[string]string) Environment
Map is an implementation of Environment that uses a given map[string]string to emulate a set of environment variables. Useful for testing.
m := Map(map[string]string {...})
func f(e env.Environment) {
e.Getenv("FOOBAR")
}
type Parser ¶
The Parser interface is what must be implemented to support decoding an environment variable into a custom type.
func Bool ¶
Bool is used to extract an environment variable into a Go bool. If required is true, then an error is returned if the environment variable is not set or is empty.
func BoolOr ¶ added in v0.3.2
BoolOr is used to extract an environment variable into a Go bool. If the environment variable is not set or is empty, then the alt value is used instead.
func Float ¶
Float is used to extract an environment variable into a Go float64. If required is true, then an error is returned if the environment variable is not set or is empty.
func FloatOr ¶ added in v0.3.2
FloatOr is used to extract an environment variable into a Go float64. If the environment variable is not set or is emty, then the alt value is used instead.
func Int ¶
Int is used to extract an environment variable into a Go int. If required is true, then an error is returned if the environment variable is not set or is empty.
func IntOr ¶ added in v0.3.2
IntOr is used to extract an environment variable into a Go int. If the environment variable is not set or is empty, then the alt value is used instead.
func Secret ¶ added in v0.3.1
Secret is used to extract an environment variable into a Go concel.Text object. If required is true, then an error is returned if the environment variable is not set or is empty.