Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load loads environment variables into the given struct and validates the constraints specified in the struct tags
e.g. `env:"ENVIRONMENT;oneof=development,test,staging,production"`
will load the environment variable `ENVIRONMENT` and validate
that it is one of the values in the `oneof` constraint.
valid constraints:
- optional: the environment variable does not need to exist and be set
- oneof: the environment variable must be one of the values in the `oneof` constraint list (separeted by commas)
- min: the environment variable must be greater than or equal to the value in the `min` constraint
- regex: the environment variable must match the regex pattern in the `regex` constraint
- format: the environment variable must match the format in the `format` constraint (only URL is supported)
example:
type AppEnv struct {
Environment string `env:"ENVIRONMENT;oneof=development,test,staging,production"`
Version float64 `env:"VERSION;"`
ApiURL string `env:"API_URL;;format=URL"`
Concurrency int `env:"CONCURRENCY;optional;min=1"`
}
appEnv := AppEnv{}
appenv.Load(&appEnv)
appEnv.Environment // "development"
Make sure to pass a pointer to the struct, otherwise it will panic Load will return an error if the environment variables are not set (unless marked as optional) or if the value does not match the constraints
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.