Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidConfig = errors.New("config: invalid config must be a pointer to struct")
)
ErrInvalidConfig is returned when the config is not a pointer to struct.
Functions ¶
func MustParse ¶
MustParse parses the config and panics if an error occurs. See Parse for more information. MustParse is a wrapper around Parse.
func Parse ¶
Parse parses the config, the config must be a pointer to struct and the struct can contain nested structs. The prefix is used to prefix the environment variables. For example, if the prefix is "app" and the struct contains a field named "Host", the environment variable will be "APP_HOST". If the struct contains a nested struct, the prefix will be the original prefix plus the nested struct name. For example, if the prefix is "app" and the nested struct is named "DB", the environment variable will be "APP_DB_HOST". Parse take an optional list of .env files to load. If the .env file exists, it will be loaded before parsing the config. By default, Parse will look for a .env file and parse it.
Types ¶
type Field ¶ added in v1.0.3
type Field struct { Name string Field reflect.Value Key string // The key used to look up the value in the environment. EnvKey string // The environment variable name used when overriding the default key. Tags reflect.StructTag Required bool Default string }
Field represents a field in a struct.
type FieldError ¶
type FieldError struct {
// contains filtered or unexported fields
}
FieldError is returned when a field cannot be parsed.
func (*FieldError) Error ¶
func (e *FieldError) Error() string
Error returns the error message for the FieldError. It includes the field name, the field value, the field type and the error returned by the parser.