Documentation
¶
Overview ¶
Package autoconfig wraps a JSON or YAML configuration stored on disk that is queryable using the Get* functions.
The configuration file will be watched for changes after the initial load. Whenever the file has changed, each validation function will be called in the order they were added.
Index ¶
- Variables
- type Config
- func (c *Config) AddValidator(f func(old, new *Config) error)
- func (c *Config) Default(key string, value interface{})
- func (c *Config) Get(path string) string
- func (c *Config) GetAll(path string) []string
- func (c *Config) GetFloat(path string) float64
- func (c *Config) GetInt(path string) int
- func (c *Config) GetMapList(path string) []map[string]interface{}
- func (c *Config) GetRaw(path string) interface{}
- func (c *Config) Immutable(key string)
- func (c *Config) Load() error
- func (c *Config) Required(key string)
- func (c *Config) Watch(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
var Fs = afero.NewOsFs()
Functions ¶
This section is empty.
Types ¶
type Config ¶
Config wraps a JSON/YAML configuration stored on disk and provides functions to query it.
func (*Config) AddValidator ¶
AddValidator adds a function that will be called whenever the config file changes. The function will be passed both the old and new configurations. If the function returns an error, the new configuration will not be applied. The validation function *may* modify the new config but *must not* modify the old config.
func (*Config) Get ¶
Get looks up a configuration item in dotted path notation and returns the first (or only) value in string form. Example: c.Get("spanner.database.path")
func (*Config) GetAll ¶
Get looks up a configuration item in dotted path notation and returns a list of values.
func (*Config) GetFloat ¶
GetFloat looks up a configuration item in dotted path notation and returns the first (or only) value in float64 form.
func (*Config) GetInt ¶
GetFloat looks up a configuration item in dotted path notation and returns the first (or only) value in int form.
func (*Config) GetMapList ¶ added in v1.2.1
GetMapList looks up a configuration item and returns a list of maps for each.
func (*Config) GetRaw ¶
GetRaw looks up the raw configuration item and does not do any conversion to a particular type. This is generally only used by the other Get* functions but is exposed for convenience.
func (*Config) Immutable ¶
Immutable marks a configuration entry as immutable. If the value changes when the configuration is updated, the new configuration will be rejected.