Documentation
¶
Index ¶
- func Flatten(m map[string]interface{}) map[string]interface{}
- func GetValue(m map[string]interface{}, keysToFind []string) interface{}
- func MergeEnvVar(m, envVars ConfigMap) map[string]interface{}
- func MergeKeys(m1, m2 ConfigMap) map[string]interface{}
- func SetValue(m map[string]interface{}, keysToFind []string, value interface{}) map[string]interface{}
- type Config
- func (c *Config) ConfigFileMerge(s string) error
- func (c *Config) Get(k string) interface{}
- func (c *Config) Immutable() *Config
- func (c *Config) LoadConfigs(configFiles ...string) (err error)
- func (c *Config) MustBool(key string, must bool) bool
- func (c *Config) MustEnvString(key, must string) string
- func (c *Config) MustInt(key string, must int) int
- func (c *Config) MustInt32(key string, must int32) int32
- func (c *Config) MustInt64(key string, must int64) int64
- func (c *Config) MustString(key, must string) string
- func (c *Config) Set(k string, v interface{})
- func (c *Config) SetConfigMap(cm ConfigMap) *Config
- func (c *Config) Unmarshal(s any) error
- func (c *Config) WithEnv(envs ...string) *Config
- type ConfigEnvAlias
- type ConfigMap
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MergeEnvVar ¶
MergeEnvVar merge Env variables into placeholders
Types ¶
type Config ¶
type Config struct {
ConfigMap ConfigMap
EnvConfigMap ConfigMap
Defaults ConfigMap
EnvAlias ConfigEnvAlias
// contains filtered or unexported fields
}
func New ¶
func New() *Config
New returns a new Config instance with empty ConfigMap and EnvConfigMap.
func NewWithParams ¶ added in v1.1.0
NewWithParams returns a new Config instance with provided defaults and env alias.
func (*Config) ConfigFileMerge ¶
ConfigFileMerge read configs from file and merge the config into ConfigMap if Key exist previosly in ConfigMap, the value will be overridden by the value from the file
func (*Config) Get ¶
Get return value from given key, and return empty string if key don't exist key can be passed in `dot-notation`
func (*Config) Immutable ¶ added in v1.0.0
Immutable prevents any future mutation to the Config. After calling Immutable, Set, SetConfigMap, ConfigFileMerge, and WithEnv become no-ops. LoadConfigs still works when called after Immutable — it uses internal write paths to apply defaults and env vars.
func (*Config) LoadConfigs ¶
LoadConfig is a function to load the configurations in ConfigMap from the provided config files, and merge with env variables if exist If no config files provided, apply defaults + env alias overrides This is a convenience method that calls LoadConfigs with the provided files.
func (*Config) MustBool ¶
MustBool returns the value associated with the key as a int64 or a default value if 0.
func (*Config) MustEnvString ¶
MustString returns the value associated with the key as a string or a default value if empty string.
func (*Config) MustInt ¶
MustInt returns the value associated with the key int or a default value if 0.
func (*Config) MustInt32 ¶
MustInt32 returns the value associated with the key as a int32 or a default value if 0.
func (*Config) MustInt64 ¶
MustInt64 returns the value associated with the key as a int64 or a default value if 0.
func (*Config) MustString ¶
MustString returns the value associated with the key as a string or a default value if empty string.
func (*Config) Set ¶
Set add or update value from given key. key can be passed in `dot-notation`. If Immutable() has been called, Set is a no-op.
func (*Config) SetConfigMap ¶
SetConfigMap sets the entire ConfigMap. If the Config is immutable, this is a no-op.
type ConfigEnvAlias ¶ added in v1.1.0
type Params ¶ added in v1.1.0
type Params struct {
Defaults ConfigMap
EnvAlias ConfigEnvAlias
}