Documentation
¶
Index ¶
- type Config
- type ConfigOptions
- func DefaultOptions() []ConfigOptions
- func KeyDelimiter(keyDelimiter string) ConfigOptions
- func Tag(structTag, validateTag string) ConfigOptions
- func WithEnvConfigPathOverload(configFilepathENV string) ConfigOptions
- func WithExpandEnvVars() ConfigOptions
- func WithLoadDotEnv(envDotFilePath string) ConfigOptions
- func WithLoadFromConfigFile(Filepath string, ErrIfFileNotFound bool) ConfigOptions
- func WithLoadFromEnvVars(EnvPrefix string) ConfigOptions
- func WithValidateByFunc(stopOnFirstErr bool, recursive bool) ConfigOptions
- func WithValidateByTags() ConfigOptions
- func WithoutEnvConfigPathOverload() ConfigOptions
- func WithoutExpandEnvVars() ConfigOptions
- func WithoutLoadDotEnv() ConfigOptions
- func WithoutLoadFromConfigFile() ConfigOptions
- func WithoutLoadFromEnvVars() ConfigOptions
- func WithoutValidateByFunc() ConfigOptions
- func WithoutValidateByTags() ConfigOptions
- type ErrValidationErrors
- type ErrValidationFunc
- type ErrValidationTag
- type Validatable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config Loads and WithValidateByTags Arbitrary structs based on options (set at constructing)
func NewConfig ¶
func NewConfig(opts ...ConfigOptions) (*Config, error)
NewConfig Create config Loader/Validator according to options.
type ConfigOptions ¶
ConfigOptions Modify Config Options Accordingly
func DefaultOptions ¶ added in v0.0.2
func DefaultOptions() []ConfigOptions
DefaultOptions Returns The Default Configuro Options
func KeyDelimiter ¶ added in v0.0.3
func KeyDelimiter(keyDelimiter string) ConfigOptions
KeyDelimiter Сhange default key delimiter.
func WithEnvConfigPathOverload ¶ added in v0.0.2
func WithEnvConfigPathOverload(configFilepathENV string) ConfigOptions
WithEnvConfigPathOverload Allow to override Config file Path with an Env Variable
func WithExpandEnvVars ¶ added in v0.0.2
func WithExpandEnvVars() ConfigOptions
WithExpandEnvVars Expand config values with ${ENVVAR} with the value of ENVVAR in environment variables. Example: ${DB_URI}:3201 ==> localhost:3201 (Where $DB_URI was equal "localhost" ) You can set default if ENVVAR is not set using the following format ${ENVVAR|defaultValue}
func WithLoadDotEnv ¶ added in v0.0.2
func WithLoadDotEnv(envDotFilePath string) ConfigOptions
WithLoadDotEnv Allow loading .env file (notice that this is application global not to this config instance only)
func WithLoadFromConfigFile ¶ added in v0.0.2
func WithLoadFromConfigFile(Filepath string, ErrIfFileNotFound bool) ConfigOptions
WithLoadFromConfigFile Load Config from file provided by filepath.
- Supported Formats/Extensions (.yml, .yaml, .toml, .json)
- ErrIfFileNotFound let you determine behavior when files is not found. Typically if you rely on Environment Variables you may not need to Error if file is not found.
func WithLoadFromEnvVars ¶ added in v0.0.2
func WithLoadFromEnvVars(EnvPrefix string) ConfigOptions
WithLoadFromEnvVars Load Configuration from Environment Variables if they're set.
- Require Environment Variables to prefixed with the set prefix (All CAPS)
- For Nested fields replace `.` with `_` and if key itself has any `_` replace it with `__` (e.g `config.host` to be `CONFIG_HOST`)
- Arrays can be declared in environment variables using 1. comma separated list. 2. json encoded array in a string.
- Maps and objects can be declared in environment using a json encoded object in a string.
func WithValidateByFunc ¶ added in v0.0.2
func WithValidateByFunc(stopOnFirstErr bool, recursive bool) ConfigOptions
WithValidateByFunc Validate struct by calling the Validate() function on every type that implement Validatable interface. - stopOnFirstErr will abort validation after the first error. - recursive will call Validate() on nested interfaces where the parent itself is also Validatable.
func WithValidateByTags ¶ added in v0.0.2
func WithValidateByTags() ConfigOptions
WithValidateByTags Validate using struct tags.
func WithoutEnvConfigPathOverload ¶ added in v0.0.2
func WithoutEnvConfigPathOverload() ConfigOptions
WithoutEnvConfigPathOverload Disallow overriding Config file Path with an Env Variable
func WithoutExpandEnvVars ¶ added in v0.0.2
func WithoutExpandEnvVars() ConfigOptions
WithoutExpandEnvVars Disable Expanding Environment Variables in Config.
func WithoutLoadDotEnv ¶ added in v0.0.2
func WithoutLoadDotEnv() ConfigOptions
WithoutLoadDotEnv disable loading .env file into Environment Variables
func WithoutLoadFromConfigFile ¶ added in v0.0.2
func WithoutLoadFromConfigFile() ConfigOptions
WithoutLoadFromConfigFile Disable loading configuration from a file.
func WithoutLoadFromEnvVars ¶ added in v0.0.2
func WithoutLoadFromEnvVars() ConfigOptions
WithoutLoadFromEnvVars will not load configuration from Environment Variables.
func WithoutValidateByFunc ¶ added in v0.0.2
func WithoutValidateByFunc() ConfigOptions
WithoutValidateByFunc Disable validating using Validatable interface.
func WithoutValidateByTags ¶ added in v0.0.2
func WithoutValidateByTags() ConfigOptions
WithoutValidateByTags Disable validate using struct tags.
type ErrValidationErrors ¶ added in v0.0.2
type ErrValidationErrors struct {
// contains filtered or unexported fields
}
ErrValidationErrors Error that hold multiple errors.
func (*ErrValidationErrors) Errors ¶ added in v0.0.2
func (e *ErrValidationErrors) Errors() []error
Errors Return a list of Errors held inside ErrValidationErrors.
func (*ErrValidationErrors) Unwrap ¶ added in v0.0.2
func (e *ErrValidationErrors) Unwrap() error
Unwrap to support errors IS|AS
type ErrValidationFunc ¶ added in v0.0.2
type ErrValidationFunc struct {
// contains filtered or unexported fields
}
ErrValidationFunc Error if validation failed by Validatable Interface.
func (*ErrValidationFunc) Error ¶ added in v0.0.2
func (e *ErrValidationFunc) Error() string
func (*ErrValidationFunc) Unwrap ¶ added in v0.0.2
func (e *ErrValidationFunc) Unwrap() error
Unwrap to support errors IS|AS
type ErrValidationTag ¶ added in v0.0.2
type ErrValidationTag struct {
// contains filtered or unexported fields
}
ErrValidationTag Error if validation failed by a tag
func (*ErrValidationTag) Error ¶ added in v0.0.2
func (e *ErrValidationTag) Error() string
func (*ErrValidationTag) Unwrap ¶ added in v0.0.2
func (e *ErrValidationTag) Unwrap() error
Unwrap to support errors IS|AS
type Validatable ¶
type Validatable interface {
Validate() error
}
Validatable Any Type that Implements this interface will have its WithValidateByTags() function called when validating config.