# README
Package env handles environment variables in a structured manner. It uses reflection
to set fields on a struct pointer passed to the main public method, Populate
.
Example (from the test):
type subEnv struct {
SubEnvRequiredString string `env:"SUB_ENV_REQUIRED_STRING,required"`
SubEnvOptionalString string `env:"SUB_ENV_OPTIONAL_STRING"`
SubEnvOptionalUint16Default uint16 `env:"SUB_ENV_OPTIONAL_UINT16_DEFAULT,default=1024"`
}
type testEnv struct {
RequiredString string `env:"REQUIRED_STRING,required"`
OptionalString string `env:"OPTIONAL_STRING"`
OptionalInt int `env:"OPTIONAL_INT"`
OptionalBool bool `env:"OPTIONAL_BOOL"`
SubEnv subEnv
Struct struct {
StructOptionalInt int `env:"STRUCT_OPTIONAL_INT"`
}
OptionalStringDefault string `env:"OPTIONAL_STRING_DEFAULT,default=foo"`
}
To populate this, one would call:
testEnv := &testEnv{}
if err := env.Populate(testEnv); err != nil {
return err
}
# Functions
Main runs the common functionality needed in a go main function.
NewEnvFileDecoder returns a new Decoder that decodes an env file of the form key=value.
NewJSONDecoder returns a new Decoder that decodes a JSON object.
Populate populates an object with environment variables.
# Interfaces
Decoder decodes an env file.