Documentation ¶
Index ¶
- func Env(key string, val *string)
- func EnvBool(key string, val *bool)
- func EnvFile(fn string) (string, error)
- func EnvInt(key string, val *int)
- func EnvInt64(key string, val *int64)
- func EnvList(key string, val *[]string)
- func IsValid(cfg any) error
- func LoadEnv(envFile string) error
- func LoadEnvFile(fn string) error
- func LoadOverrides(cfg any) error
- func LoadToml(cfg any, fn string) error
- type FieldError
- type Section
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvFile ¶
EnvFile returns full path to .env file if it exists in the current working directory. If file doesn't exists, empty string returned
suffix is used to append to the .env file, for example for "dev" suffix, ".env.dev" will be looked up
func IsValid ¶
IsValid validates Config. If any of the fields in the config struct implement Section interface (i.e. have IsValid() func) it is called.
Error returned if any of the IsValid returns false
func LoadEnv ¶
LoadEnv loads .env file from the current working directory if it exists envFile is just an ".env" or ".env.dev" without full file path
To load using full file path, use LoadEnvFile
func LoadEnvFile ¶
LoadEnvFile reads all strings from fn file and loads it into the environment The format of the string is key=value
func LoadOverrides ¶
LoadOverrides loads data into struct from environment variables.
Names of environment vars are specified using "env" structure tag.
The following patterns are supported. Example:
type Config struct {
// Standalone field with a tag Var1 string `env:"SOME_VAR"` // pointer to basic types Var1 string `env:"SOME_VAR"` // Nested structure without tag Section ConfigSection // Nested structure with a tag, which will be used as a prefix // with underscore for any tags in the nested structure. // // Fore example in this case "SERVICE_" will be prefixed // for any var name specified in the ConfigSection structue Section2 ConfigSection `env:"SERVICE"` }
Types ¶
type FieldError ¶
func (FieldError) Error ¶
func (e FieldError) Error() string