Documentation
¶
Overview ¶
Package config is a wrapper around viper that provides a consistent way to access configuration values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidInput is returned when the input is not a pointer to a struct or a struct. ErrInvalidInput = errors.New("input must be a struct or a pointer to a struct") )
Functions ¶
func Attach ¶
Attach attaches the config to all fields of the provided struct. The input must be a pointer to a struct. To attach a config to a field, the field must be of attachable interface and be exported.
func Decode ¶
func Decode(input interface{}, output interface{}) error
Decode takes a struct as input end transforms the Value fields into the output struct fields. It uses mapstructure to decode the map into the output struct. It is important to remember that the input field's key should be the same as the `config` tag of the output field. Example:
type config struct {
ApiKey Value[string]
}
type concreteConfig struct {
ApiKey string `config:"api_key"`
}
var cfg config = config{
ApiKey: config.String("api_key"),
}
var concreteCfg concreteConfig
err := Flatten(cfg, &concreteCfg)
Types ¶
type Option ¶
type Option[T any] func(*configValue[T])
func WithDefault ¶
WithDefault sets the default value for the config value.
Click to show internal directories.
Click to hide internal directories.