Documentation ¶
Index ¶
- Variables
- func GetRangeValues(value string) (min string, max string, minBracket string, maxBracket string, err error)
- func Parse(conf interface{}) error
- func Print(config interface{})
- func ValidateRangeFields(valueStr, constraint string) error
- type EnvParser
- type EnvProvider
- type OSEnvProvider
- type ParseError
- type Secret
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotStructPtr = errors.New("must be a pointer to a struct")
ErrNotStructPtr indicates a type is not a pointer to a struct.
Functions ¶
func GetRangeValues ¶
func GetRangeValues(value string) (min string, max string, minBracket string, maxBracket string, err error)
GetRangeValues reads up the given range constraint and returns the values, or an error if the constraint is malformed or could not be parsed.
func Parse ¶
func Parse(conf interface{}) error
Parse populates a struct with the retrieved values from environment variables described by struct tags and applies the defined validations.
Example ¶
c := struct { Name string `env:"ENV_NAME"` Num int `env:"ENV_NUMBER"` }{} if err := os.Setenv("ENV_NAME", "example"); err != nil { panic(err) } if err := os.Setenv("ENV_NUMBER", "1548"); err != nil { panic(err) } if err := Parse(&c); err != nil { log.Fatal(err) } fmt.Println(c)
Output: {example 1548}
func Print ¶
func Print(config interface{})
Print the name of the struct with Title case in blue color with followed by a newline, then print all fields formatted as '- field name: field value` separated by newline.
func ValidateRangeFields ¶
ValidateRangeFields validates if the given range is proper. Ranges are optional, empty values are valid.
Types ¶
type EnvProvider ¶
EnvProvider ...
type ParseError ¶
ParseError occurs when a struct field cannot be set.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error implements builtin errors.Error.