Documentation ¶
Index ¶
- func AddValidator(v Validator)
- func AtHob(hob string, configStruct interface{}) error
- func AtServiceType(hob string, serviceType string, configStruct interface{}) error
- func AtServiceTypes(hob string, configStructs interface{}) error
- func LastLoaded() (string, time.Time)
- func Load(r io.Reader) error
- func LoadFromFile(fn string) (err error)
- func Raw() []byte
- func SetLoader(loader *Loader)
- func SubscribeChanges() <-chan bool
- func WaitUntilLoaded(d time.Duration) bool
- func WaitUntilReloaded(d time.Duration) bool
- type Config
- func (c *Config) AddValidator(v Validator)
- func (c *Config) AtPath(path ...string) ConfigElement
- func (c *Config) LastLoaded() (string, time.Time)
- func (c *Config) Load(r io.Reader) error
- func (c *Config) Raw() []byte
- func (c *Config) SubscribeChanges() <-chan bool
- func (c *Config) WaitUntilLoaded(d time.Duration) bool
- func (c *Config) WaitUntilReloaded(d time.Duration) bool
- type ConfigElement
- type JSONElement
- func (c *JSONElement) AsBool() bool
- func (c *JSONElement) AsDistance(def string) (value distance.Distance)
- func (c *JSONElement) AsDuration(def string) (value time.Duration)
- func (c *JSONElement) AsFloat64(def float64) (value float64)
- func (c *JSONElement) AsHostnameArray(defPort int) []string
- func (c *JSONElement) AsInt(def int) (value int)
- func (c *JSONElement) AsJson() []byte
- func (c *JSONElement) AsString(def string) string
- func (c *JSONElement) AsStringArray() []string
- func (c *JSONElement) AsStringMap() map[string]string
- func (c *JSONElement) AsStruct(val interface{}) error
- func (c *JSONElement) AtPath(path ...string) ConfigElement
- func (c *JSONElement) Decrypt() (ConfigElement, error)
- func (c *JSONElement) DecryptWithContext(ctx map[string]string) (ConfigElement, error)
- type Loader
- type MissingConfigError
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddValidator ¶
func AddValidator(v Validator)
AddValidator adds a validator function to the default config instance.
func AtServiceType ¶
AtServiceType reads service type config in a struct. Returns error if config is missing.
func AtServiceTypes ¶
AtServiceTypes reads the service config for all service types for a hob. configStruct is expected to be a map[string] -> serviceType config struct
func LoadFromFile ¶
LoadFromFile will load config from a flat text file containing JSON into the default instance
func SetLoader ¶
func SetLoader(loader *Loader)
LoadFromService will load config from the config service into the default instance
func SubscribeChanges ¶
func SubscribeChanges() <-chan bool
SubscribeChanges is a wrapper around DefaultInstance.SubscribeChanges
func WaitUntilLoaded ¶
WaitUntilLoaded wraps DefaultInstance.WaitUntilLoaded
func WaitUntilReloaded ¶
WaitUntilReloaded wraps DefaultInstance.WaitUntilReloaded
Types ¶
type Config ¶
type Config struct { // Used for decrypting secrets Service, Region, Env string Encryptor encryption.Encryptor // contains filtered or unexported fields }
Config represents a bunch of config settings
func (*Config) AddValidator ¶
AddValidator adds a config validation function to a slice of validators deprecated
func (*Config) AtPath ¶
func (c *Config) AtPath(path ...string) ConfigElement
AtPath will get a ConfigElement at the specified path
func (*Config) LastLoaded ¶
LastLoaded will return the time we last loaded config, along with the hash
func (*Config) SubscribeChanges ¶
SubscribeChanges will yield a channel which will then receive a boolean whenever the loaded configuration changes (depending on the exact loader used)
func (*Config) WaitUntilLoaded ¶
WaitUntilLoaded waits for a maximum amount of duration d for the config to be successfully loaded. The idea is that we would prefer to soldier on if we cannot load config, but we don't mind delaying service boot times a little bit if it means they start off with some config loaded
func (*Config) WaitUntilReloaded ¶
WaitUntilReloaded waits for a maximum amount of duration d for the config to be successfully loaded. This contrasts with WaitUntilLoaded in that it only returns after the config has been refreshed; it will not return immediately in the case that config is already cached
type ConfigElement ¶
type ConfigElement interface { AsString(def string) string AsBool() bool AsInt(def int) int AsFloat64(def float64) float64 AsDuration(def string) time.Duration AsStringArray() []string AsHostnameArray(defPort int) []string AsStringMap() map[string]string AsStruct(val interface{}) error AsJson() []byte Decrypt() (ConfigElement, error) AtPath(path ...string) ConfigElement }
ConfigElement represents some specific piece of config, that we have drilled down to
func AtPath ¶
func AtPath(path ...string) ConfigElement
AtPath is a wrapper around DefaultInstance.AtPath
type JSONElement ¶
JSONElement is the default implementation of ConfigElement
func (*JSONElement) AsBool ¶
func (c *JSONElement) AsBool() bool
AsBool will retrieve a single config value as a string. It works with our config service and will automatically interpret a string of "true" as a boolean true, and treat undefined as false.
func (*JSONElement) AsDistance ¶
func (c *JSONElement) AsDistance(def string) (value distance.Distance)
AsDistance will retrieve a single config value as a distance, parsing a string like "10mi" or "5km" etc.
func (*JSONElement) AsDuration ¶
func (c *JSONElement) AsDuration(def string) (value time.Duration)
AsDuration will retrieve a single config value as a duration, parsing a string like "10ms" or "5s" etc.
func (*JSONElement) AsFloat64 ¶
func (c *JSONElement) AsFloat64(def float64) (value float64)
AsFloat64 will retrieve a single config value as a float.
func (*JSONElement) AsHostnameArray ¶
func (c *JSONElement) AsHostnameArray(defPort int) []string
AsHostnameArray will retrieve an array of config values, where each one is a string made up of a hostname:port. Any values defined in config without a :port bit will have this automatically added.
func (*JSONElement) AsInt ¶
func (c *JSONElement) AsInt(def int) (value int)
AsInt will retrieve a single config value as an integer.
func (*JSONElement) AsJson ¶
func (c *JSONElement) AsJson() []byte
AsJson will retrieve a single config value, as JSON-encoded data in byte form.
func (*JSONElement) AsString ¶
func (c *JSONElement) AsString(def string) string
AsString will retrieve a single config value as a string. It will return a blank string if there is no value corresponding to the supplied path, or alternatively the supplied default value.
func (*JSONElement) AsStringArray ¶
func (c *JSONElement) AsStringArray() []string
AsStringArray will retrieve an array of config values, each as a string.
func (*JSONElement) AsStringMap ¶
func (c *JSONElement) AsStringMap() map[string]string
AsStringMap will retrieve a map of string config values with the children of the specified path being string keys to their descendents.
func (*JSONElement) AsStruct ¶
func (c *JSONElement) AsStruct(val interface{}) error
AsStruct will retrieve a single config value, marshaling it into the provided empty struct.
func (*JSONElement) AtPath ¶
func (c *JSONElement) AtPath(path ...string) ConfigElement
AtPath will get a ConfigElement at the specified path
func (*JSONElement) Decrypt ¶
func (c *JSONElement) Decrypt() (ConfigElement, error)
func (*JSONElement) DecryptWithContext ¶
func (c *JSONElement) DecryptWithContext(ctx map[string]string) (ConfigElement, error)
type Loader ¶
type Loader struct { tomb.Tomb // contains filtered or unexported fields }
Loader represents a loader of configuration. It automatically reloads when it receives notification that it should do so on its changes channel, and also every configPollInterval
func NewFileLoader ¶
NewFileLoader returns a loader that reads config from file fn
type MissingConfigError ¶
type MissingConfigError struct {
// contains filtered or unexported fields
}
func (MissingConfigError) Error ¶
func (e MissingConfigError) Error() string