Documentation
¶
Overview ¶
Package config provides application configuration loading and binding.
Index ¶
- func Bind[T any](c *T, prefix string, v *viper.Viper) *T
- func LoadRemoteSecret(name string) (string, error)
- type Binder
- type Cache
- type CmdBinder
- type Configurable
- type Configuration
- func (c *Configuration) AddModifier(fn Modifier)
- func (c *Configuration) Bind(_ string, v *viper.Viper)
- func (c *Configuration) Core() *Configuration
- func (c *Configuration) Load(cmd *cobra.Command, config any, environment string) error
- func (c *Configuration) Loaded(*Configuration)
- func (c *Configuration) Ready() bool
- func (c *Configuration) SetConfigDirName(dirName string)
- func (c *Configuration) SetConfigFile(path string)
- func (c *Configuration) SetConfigName(name string)
- func (c *Configuration) Validate(validate *validation.Validate) error
- type Log
- type Logger
- type Modifier
- type Validatable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadRemoteSecret ¶
LoadRemoteSecret loads a remote secret from configuration provided in environment variable.
Environment variable name is expected to be in the format:
<name>_FILE - path to the file containing the secret
Types ¶
type Binder ¶
Binder is an interface that can be implemented by configuration sections to bind to configuration file.
type Cache ¶
type Cache struct {
Type cache.Type `mapstructure:"type" validate:"required,oneof=memory redis redis-cluster redis-sentinel"`
TTL time.Duration `mapstructure:"ttl" validate:"omitempty,min=0"`
ConnectionString string `mapstructure:"connection" validate:"omitempty"`
Password string `mapstructure:"password" validate:"omitempty"`
KeyPrefix string `mapstructure:"key_prefix" validate:"omitempty"`
}
Cache is the cache configuration section.
type CmdBinder ¶ added in v0.3.0
CmdBinder is an interface that can be implemented by configuration sections to bind to command line arguments.
type Configurable ¶
type Configurable interface {
Core() *Configuration
Loaded(conf *Configuration)
}
Configurable is an interface that can be implemented by extended configuration.
type Configuration ¶
type Configuration struct {
// Cache configuration section.
Cache *Cache
// Log configuration section.
Log *Log
// contains filtered or unexported fields
}
Configuration for the application.
func (*Configuration) AddModifier ¶ added in v0.30.0
func (c *Configuration) AddModifier(fn Modifier)
AddModifier registers a function that will be called during Load to modify/configure the underlying configuration engine. Use this to set defaults, bind environment variables, or otherwise fine-tune settings based on runtime info.
func (*Configuration) Bind ¶
func (c *Configuration) Bind(_ string, v *viper.Viper)
Bind configuration section to the configuration backend/instance.
func (*Configuration) Core ¶
func (c *Configuration) Core() *Configuration
Core returns the core configuration.
func (*Configuration) Loaded ¶
func (c *Configuration) Loaded(*Configuration)
Loaded receives loaded core configuration.
func (*Configuration) Ready ¶
func (c *Configuration) Ready() bool
Ready returns true if the configuration has been loaded.
func (*Configuration) SetConfigDirName ¶
func (c *Configuration) SetConfigDirName(dirName string)
SetConfigDirName sets the name of the directory where the config file is located under common config locations.
func (*Configuration) SetConfigFile ¶
func (c *Configuration) SetConfigFile(path string)
SetConfigFile explicitly defines the path, name and extension of the config file.
func (*Configuration) SetConfigName ¶
func (c *Configuration) SetConfigName(name string)
SetConfigName sets name for the config file. Does not include extension.
func (*Configuration) Validate ¶
func (c *Configuration) Validate(validate *validation.Validate) error
Validate the configuration.
type Log ¶ added in v0.21.0
type Log struct {
// Type of the logger (defaults to `console`, allowed also `file` or other registered logging targets).
Type string `mapstructure:"type" validate:"omitempty"`
// Level of the logging output (defaults to `debug` in development environment and `info` in staging and production).
Level string `mapstructure:"level" validate:"omitempty,oneof=debug info warn error dpanic panic fatal"`
// Format of the logging output (defaults to `console` in development environment and `ecsjson` in staging and production).
Format string `mapstructure:"format" validate:"omitempty,oneof=console json ecsjson"`
// Output location (defaults to stderr)
Output string `mapstructure:"output"`
// Stacktrace enables stack traces for error level and above regardless of environment.
// Can be set via LOG_STACKTRACE environment variable.
Stacktrace bool `mapstructure:"stacktrace"`
// Secondary logging output configuration.
Secondary *Logger `mapstructure:"secondary" validate:"omitempty"`
}
Log configuration section.
type Logger ¶ added in v0.22.0
type Logger struct {
// Type of the logger (allowed values are `console`, `file` and other registered logging targets).
Type string `mapstructure:"type" validate:"required"`
// Level of the logging output (defaults to `info`).
Level string `mapstructure:"level" validate:"omitempty,oneof=debug info warn error dpanic panic fatal"`
// Format of the logging output (defaults to `console` in development environment and `ecsjson` in staging and production).
Format string `mapstructure:"format" validate:"omitempty,oneof=console json ecsjson"`
// Output location (type sepcific output location).
Output string `mapstructure:"output" validate:"omitempty"`
}
Logger represents the logging output configuration.
type Modifier ¶ added in v0.30.0
Modifier is a function that receives the underlying configuration backend/instance and may call SetDefault, BindEnv, or adjust other settings. It is exposed so other packages (for example server) can accept these as options without importing the configuration backend directly.
type Validatable ¶
type Validatable interface {
Validate(v *validation.Validate) error
}
Validatable is an interface that can be implemented by configuration section to validate the configuration.