Documentation
¶
Overview ¶
Package envconfig provides functionality to easily load config into your struct.
Index ¶
- Variables
- func Set(config any, opts ...option) error
- func WithActiveProfile(activeProfile string) option
- func WithDecoders(decoders map[reflect.Type]DecoderFunc) option
- func WithFilepath(filepath string) option
- func WithPrefix(prefix string) option
- type DecoderFunc
- type EnvironmentVariableSource
- type FieldConversionError
- type FileReadError
- type FileSource
- type FileTypeValidationError
- type FlagSource
- type IncompatibleOptionsError
- type InvalidConfigTypeError
- type InvalidOptionConversionError
- type OpenFileError
- type ParseError
- type PrefixOptionError
- type ReplacementError
- type RequiredFieldError
- type SetEnvironmentVariableError
- type Setter
- type UnsupportedFieldTypeError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSyntax = errors.New("invalid syntax")
ErrSyntax indicates that a line is invalid syntax.
Functions ¶
func Set ¶
Set will parse multiple sources for config values, and use these values to populate the passed in config struct.
Example ¶
type Config struct {
Value string `env:"VALUE"`
}
os.Setenv("VALUE", "value")
var cfg Config
envconfig.Set(&cfg)
fmt.Println(cfg.Value)
Output: value
func WithActiveProfile ¶
func WithActiveProfile(activeProfile string) option
func WithDecoders ¶
func WithDecoders(decoders map[reflect.Type]DecoderFunc) option
func WithFilepath ¶
func WithFilepath(filepath string) option
WithFilepath option will cause the file provided to be used to set variables in the environment.
func WithPrefix ¶
func WithPrefix(prefix string) option
WithPrefix option will add the prefix to before every set and retrieval from env.
Types ¶
type EnvironmentVariableSource ¶
type EnvironmentVariableSource struct {
// contains filtered or unexported fields
}
type FieldConversionError ¶
FieldConversionError occurs when a field on the config struct fails to be set.
func (*FieldConversionError) Error ¶
func (e *FieldConversionError) Error() string
Error satisfies the error interface for FieldConversionError.
func (*FieldConversionError) Unwrap ¶
func (e *FieldConversionError) Unwrap() error
Unwrap allows FieldConversionError to be used with errors.Is and errors.As.
type FileReadError ¶
FileReadError occurs when an error occurs when scanning the .env file.
func (*FileReadError) Error ¶
func (e *FileReadError) Error() string
Error satisfies the error interface for FileReadError.
func (*FileReadError) Unwrap ¶
func (e *FileReadError) Unwrap() error
Unwrap allows FileReadError to be used with errors.Is and errors.As.
type FileSource ¶
type FileSource struct {
// contains filtered or unexported fields
}
type FileTypeValidationError ¶
type FileTypeValidationError struct {
Filepath string
}
FileTypeValidationError occurs when the .env config file fails to open.
func (*FileTypeValidationError) Error ¶
func (e *FileTypeValidationError) Error() string
Error satisfies the error interface for FileTypeValidationError.
type FlagSource ¶
type FlagSource struct{}
type IncompatibleOptionsError ¶
IncompatibleOptionsError occurs when two options are incompatible with each other, or the usage is invalid.
func (*IncompatibleOptionsError) Error ¶
func (e *IncompatibleOptionsError) Error() string
Error satisfies the error interface for FileReadError.
type InvalidConfigTypeError ¶
type InvalidConfigTypeError struct {
ProvidedType any
}
InvalidConfigTypeError occurs when config is not a pointer to a struct.
func (*InvalidConfigTypeError) Error ¶
func (e *InvalidConfigTypeError) Error() string
Error satisfies the error interface for InvalidConfigTypeError.
type InvalidOptionConversionError ¶
InvalidOptionConversionError occurs when an option is invalid for a field.
func (*InvalidOptionConversionError) Error ¶
func (e *InvalidOptionConversionError) Error() string
Error satisfies the error interface for InvalidOptionConversionError.
func (*InvalidOptionConversionError) Unwrap ¶
func (e *InvalidOptionConversionError) Unwrap() error
Unwrap allows InvalidOptionConversionError to be used with errors.Is and errors.As.
type OpenFileError ¶
type OpenFileError struct {
Err error
}
OpenFileError occurs when the .env config file fails to open.
func (*OpenFileError) Error ¶
func (e *OpenFileError) Error() string
Error satisfies the error interface for OpenFileError.
func (*OpenFileError) Unwrap ¶
func (e *OpenFileError) Unwrap() error
Unwrap allows OpenFileError to be used with errors.Is and errors.As.
type ParseError ¶
ParseError occurs when a line from the .env config file has been parsed incorrectly.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error statisfies the error interface for ParseError.
type PrefixOptionError ¶
type PrefixOptionError struct {
FieldName any
}
PrefixOptionError occurs when the prefix tag is invalid or not set on a nested struct.
func (*PrefixOptionError) Error ¶
func (e *PrefixOptionError) Error() string
Error satisfies the error interface for PrefixOptionError.
type ReplacementError ¶
type ReplacementError struct {
VariableName string
}
ReplacementError occurs when the environment variable being used for replacement is not set.
func (*ReplacementError) Error ¶
func (e *ReplacementError) Error() string
Error satisfies the error interface for ReplacementError.
type RequiredFieldError ¶
type RequiredFieldError struct {
FieldName string
}
RequiredFieldError occurs when a required field is not set and in the environment variables.
func (*RequiredFieldError) Error ¶
func (e *RequiredFieldError) Error() string
Error satisfies the error interface for RequiredFieldError.
type SetEnvironmentVariableError ¶
type SetEnvironmentVariableError struct {
Err error
}
SetEnvironmentVariableError occurs when the value is failed to be set in the environment.
func (*SetEnvironmentVariableError) Error ¶
func (e *SetEnvironmentVariableError) Error() string
Error satisfies the error interface for SetEnvironmentVariableError.
func (*SetEnvironmentVariableError) Unwrap ¶
func (e *SetEnvironmentVariableError) Unwrap() error
Unwrap allows SetEnvironmentVariableError to be used with errors.Is and errors.As.
type UnsupportedFieldTypeError ¶
type UnsupportedFieldTypeError struct {
FieldType any
}
UnsupportedFieldTypeError occurs when the a field type on the config struct is not compatible.
func (*UnsupportedFieldTypeError) Error ¶
func (e *UnsupportedFieldTypeError) Error() string
Error satisfies the error interface for UnsupportedFieldTypeError.