config

package
v0.0.0-...-cbea63e Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

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 AtHob

func AtHob(hob string, configStruct interface{}) error

AtHob reads hob config in a struct. Returns error if config is missing.

func AtServiceType

func AtServiceType(hob string, serviceType string, configStruct interface{}) error

AtServiceType reads service type config in a struct. Returns error if config is missing.

func AtServiceTypes

func AtServiceTypes(hob string, configStructs interface{}) error

AtServiceTypes reads the service config for all service types for a hob. configStruct is expected to be a map[string] -> serviceType config struct

func LastLoaded

func LastLoaded() (string, time.Time)

LastLoaded wraps DefaultInstance.LastLoaded

func Load

func Load(r io.Reader) error

Load will load config from a Reader into the default instance

func LoadFromFile

func LoadFromFile(fn string) (err error)

LoadFromFile will load config from a flat text file containing JSON into the default instance

func Raw

func Raw() []byte

Raw wraps DefaultInstance.Raw

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

func WaitUntilLoaded(d time.Duration) bool

WaitUntilLoaded wraps DefaultInstance.WaitUntilLoaded

func WaitUntilReloaded

func WaitUntilReloaded(d time.Duration) bool

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

var DefaultInstance *Config = New()

DefaultInstance is the default config instance

func New

func New() *Config

New mints a new config

func (*Config) AddValidator

func (c *Config) AddValidator(v Validator)

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

func (c *Config) LastLoaded() (string, time.Time)

LastLoaded will return the time we last loaded config, along with the hash

func (*Config) Load

func (c *Config) Load(r io.Reader) error

Load will load config from a Reader into c

func (*Config) Raw

func (c *Config) Raw() []byte

Raw returns entire raw loaded config as bytes

func (*Config) SubscribeChanges

func (c *Config) SubscribeChanges() <-chan bool

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

func (c *Config) WaitUntilLoaded(d time.Duration) bool

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

func (c *Config) WaitUntilReloaded(d time.Duration) bool

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

type JSONElement struct {
	*sjson.Json
	// contains filtered or unexported fields
}

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

func NewFileLoader(c *Config, fn string) (*Loader, error)

NewFileLoader returns a loader that reads config from file fn

func NewLoader

func NewLoader(c *Config, changes chan bool, r reader) *Loader

func (*Loader) Load

func (ldr *Loader) Load() error

Load will go and grab the config via the reader and then load it into the config

func (*Loader) Reload

func (ldr *Loader) Reload()

type MissingConfigError

type MissingConfigError struct {
	// contains filtered or unexported fields
}

func (MissingConfigError) Error

func (e MissingConfigError) Error() string

type Validator

type Validator func([]byte) bool

Validator function takes config as slice of bytes, evaluates based on some rules and returns whether the config is valid as boolean.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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