Documentation ¶
Index ¶
- type Config
- func Get() *Config
- func Loaded(s *Config) (*Config, error)
- func New() *Config
- func NewCustomWatchedFile(file string, f func(fsnotify.Event)) *Config
- func NewCustomWatchedPath(path string, name string, f func(fsnotify.Event)) *Config
- func NewDefaultWatchedFile(file string) *Config
- func NewDefaultWatchedPath(path string, name string) *Config
- func NewWithFile(file string) *Config
- func NewWithPath(path string, name string) *Config
- func (s *Config) AddConfigPath(in string)
- func (s *Config) BindEnv(input ...string) error
- func (s *Config) Get(key string) any
- func (s *Config) GetBool(key string) bool
- func (s *Config) GetInt(key string) int
- func (s *Config) GetString(key string) string
- func (s *Config) GetStringDecoded(key string) string
- func (s *Config) GetStringMap(key string) map[string]any
- func (s *Config) GetStringMapString(key string) map[string]string
- func (s *Config) GetStringSlice(key string) []string
- func (s *Config) OnConfigChange(run func(in fsnotify.Event))
- func (s *Config) ReadConfig(in io.Reader) error
- func (s *Config) ReadInConfig() error
- func (s *Config) Set(key string, value any)
- func (s *Config) SetConfigFile(in string)
- func (s *Config) SetConfigName(in string)
- func (s *Config) SetConfigType(in string)
- func (s *Config) SetEnvPrefix(in string)
- func (s *Config) Sub(key string) *Config
- func (s *Config) Unmarshal(rawVal any) error
- func (s *Config) UnmarshalKey(key string, rawVal any) error
- func (s *Config) WatchConfig()
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 is the configuration. It internally uses Viper config. We decided to create a wrapper instead of consuming Viper directly due to following reasons:
- Viper is a complex library, and we preferred using a simple config system which can be extended if need to be
- With our own Config, we can provide a stable API, even when Viper undergoes versioning updates.
Note that goarc configuration is a subset of Viper, and it may not support all the functions that are present in Viper.
func NewCustomWatchedFile ¶
NewCustomWatchedFile is to create a new config object; that has - custom listener attached
func NewCustomWatchedPath ¶
NewCustomWatchedPath is to create a new config object; that has - custom listener attached
func NewDefaultWatchedFile ¶
NewDefaultWatchedFile is to create a new config object; that has - no-op listener attached
func NewDefaultWatchedPath ¶
NewDefaultWatchedPath is to create a new config object; that has - no-op listener attached
func NewWithFile ¶
NewWithFile is to create a new config object for given file
func NewWithPath ¶
NewWithPath is to create a new config object for given path+name
func (*Config) AddConfigPath ¶
AddConfigPath adds a path for Config to search for the config file in. Can be called multiple times to define multiple search paths.
func (*Config) BindEnv ¶
BindEnv binds a Config key to a ENV variable. ENV variables are case-sensitive. If only a key is provided, it will use the env key matching the key, uppercase. EnvPrefix will be used when set when env name is not provided.
func (*Config) Get ¶
Get can retrieve any value given the key to use. Get is case-insensitive for a key. Get has the behavior of returning the value associated with the first place from where it is set. Config will check in the following order: override, flag, env, config file, key/value store, default
Get returns an interface. For a specific value use one of the Get____ methods.
func (*Config) GetStringDecoded ¶
GetStringDecoded returns the value associated with the key as a base64 decoded string.
func (*Config) GetStringMap ¶
GetStringMap returns the value associated with the key as a map of interfaces.
func (*Config) GetStringMapString ¶
GetStringMapString returns the value associated with the key as a map of strings.
func (*Config) GetStringSlice ¶
GetStringSlice returns the value associated with the key as a slice of strings.
func (*Config) OnConfigChange ¶
OnConfigChange registers callback for config change
func (*Config) ReadConfig ¶
ReadConfig will read a configuration file, setting existing keys to nil if the key does not exist in the file.
func (*Config) ReadInConfig ¶
ReadInConfig will discover and load the configuration file from disk and key/value stores, searching in one of the defined paths.
func (*Config) Set ¶
Set sets the value for the key in the override register. Set is case-insensitive for a key. Will be used instead of values obtained via flags, config file, ENV, default, or key/value store.
func (*Config) SetConfigFile ¶
SetConfigFile explicitly defines the path, name and extension of the config file. Config will use this and not check any of the config paths.
func (*Config) SetConfigName ¶
SetConfigName sets name for the config file. Does not include extension.
func (*Config) SetConfigType ¶
SetConfigType sets the type of the configuration returned by the remote source, e.g. "json".
func (*Config) SetEnvPrefix ¶
SetEnvPrefix defines a prefix that ENVIRONMENT variables will use. E.g. if your prefix is "old", the env registry will look for env variables that start with "OLD_".
func (*Config) Sub ¶
Sub returns new Config instance representing a subtree of this instance. Sub is case-insensitive for a key.
func (*Config) Unmarshal ¶
Unmarshal unmarshals the config into a Config. Make sure that the tags on the fields of the structure are properly set.
func (*Config) UnmarshalKey ¶
UnmarshalKey takes a single key and unmarshal it into given value.
func (*Config) WatchConfig ¶
func (s *Config) WatchConfig()
WatchConfig watches for any change in underlying config source