config

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

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 Get

func Get() *Config

Get loads app config, panic if app config load fails

func Loaded

func Loaded(s *Config) (*Config, error)

Loaded is to load the configuration to the config object

func New

func New() *Config

New is to create a new blank config object

func NewCustomWatchedFile

func NewCustomWatchedFile(file string, f func(fsnotify.Event)) *Config

NewCustomWatchedFile is to create a new config object; that has - custom listener attached

func NewCustomWatchedPath

func NewCustomWatchedPath(path string, name string, f func(fsnotify.Event)) *Config

NewCustomWatchedPath is to create a new config object; that has - custom listener attached

func NewDefaultWatchedFile

func NewDefaultWatchedFile(file string) *Config

NewDefaultWatchedFile is to create a new config object; that has - no-op listener attached

func NewDefaultWatchedPath

func NewDefaultWatchedPath(path string, name string) *Config

NewDefaultWatchedPath is to create a new config object; that has - no-op listener attached

func NewWithFile

func NewWithFile(file string) *Config

NewWithFile is to create a new config object for given file

func NewWithPath

func NewWithPath(path string, name string) *Config

NewWithPath is to create a new config object for given path+name

func (*Config) AddConfigPath

func (s *Config) AddConfigPath(in string)

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

func (s *Config) BindEnv(input ...string) error

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

func (s *Config) Get(key string) any

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) GetBool

func (s *Config) GetBool(key string) bool

GetBool returns the value associated with the key as a boolean.

func (*Config) GetInt

func (s *Config) GetInt(key string) int

GetInt returns the value associated with the key as an integer.

func (*Config) GetString

func (s *Config) GetString(key string) string

GetString returns the value associated with the key as a string.

func (*Config) GetStringDecoded

func (s *Config) GetStringDecoded(key string) string

GetStringDecoded returns the value associated with the key as a base64 decoded string.

func (*Config) GetStringMap

func (s *Config) GetStringMap(key string) map[string]any

GetStringMap returns the value associated with the key as a map of interfaces.

func (*Config) GetStringMapString

func (s *Config) GetStringMapString(key string) map[string]string

GetStringMapString returns the value associated with the key as a map of strings.

func (*Config) GetStringSlice

func (s *Config) GetStringSlice(key string) []string

GetStringSlice returns the value associated with the key as a slice of strings.

func (*Config) OnConfigChange

func (s *Config) OnConfigChange(run func(in fsnotify.Event))

OnConfigChange registers callback for config change

func (*Config) ReadConfig

func (s *Config) ReadConfig(in io.Reader) error

ReadConfig will read a configuration file, setting existing keys to nil if the key does not exist in the file.

func (*Config) ReadInConfig

func (s *Config) ReadInConfig() error

ReadInConfig will discover and load the configuration file from disk and key/value stores, searching in one of the defined paths.

func (*Config) Set

func (s *Config) Set(key string, value any)

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

func (s *Config) SetConfigFile(in string)

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

func (s *Config) SetConfigName(in string)

SetConfigName sets name for the config file. Does not include extension.

func (*Config) SetConfigType

func (s *Config) SetConfigType(in string)

SetConfigType sets the type of the configuration returned by the remote source, e.g. "json".

func (*Config) SetEnvPrefix

func (s *Config) SetEnvPrefix(in string)

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

func (s *Config) Sub(key string) *Config

Sub returns new Config instance representing a subtree of this instance. Sub is case-insensitive for a key.

func (*Config) Unmarshal

func (s *Config) Unmarshal(rawVal any) error

Unmarshal unmarshals the config into a Config. Make sure that the tags on the fields of the structure are properly set.

func (*Config) UnmarshalKey

func (s *Config) UnmarshalKey(key string, rawVal any) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL