Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnmarshalFromEnv ¶
func UnmarshalFromEnv(v interface{}) error
UnmarshalFromEnv parses the environment variables and stores the results in the value pointed to by v. If v is nil or not a pointer to a struct, UnmarshalFromEnv returns an env.ErrInvalidValue.
Fields tagged with "env" will have the unmarshalled env value of the matching key. If the tagged field is not exported, UnmarshalFromEnv returns env.ErrUnexportedField.
If the field has a type that is unsupported, UnmarshalFromEnv returns env.ErrUnsupportedType.
Example ¶
err := os.Setenv("int", "1") if err != nil { fmt.Println(err) } err = os.Setenv("string", "text") if err != nil { fmt.Println(err) } err = os.Setenv("BOOL", "true") if err != nil { fmt.Println(err) } cfg := struct { Int int `env:"int"` String string `env:"string,required=true"` Float float64 `env:"float,default=3.14"` Bool bool `env:"bool,BOOL"` }{} err = config.UnmarshalFromEnv(&cfg) if err != nil { fmt.Println(err) }
func UnmarshalFromFile ¶
UnmarshalFromFile decodes the file and assigns the decoded values into the out value.
Fields tagged with "mapstructure" will have the unmarshalled value of the matching key.
Example ¶
cfg := struct { String string `mapstructure:"string"` Map map[string]struct { Array []string `mapstructure:"array"` Int int `mapstructure:"int"` Float float64 `mapstructure:"float"` Bool bool `mapstructure:"bool"` } `mapstructure:"map"` }{} err := config.UnmarshalFromFile("filename.yml", &cfg) if err != nil { fmt.Println(err) }
Types ¶
This section is empty.