distconf

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = log.Logger(log.DefaultLogger.CreateChild())

DefaultLogger is used by package structs that don't have a default logger set.

View Source
var DefaultZkConfig = &ZkConfig{
	Logger: DefaultLogger,
}

DefaultZkConfig is the configuration used by new Zk readers if any config parameter is unset

Functions

This section is empty.

Types

type BackingLoader

type BackingLoader interface {
	Get() (Reader, error)
}

A BackingLoader should run a single time and get a Reader for Config

func CmdLoader

func CmdLoader(prefix string) BackingLoader

CmdLoader is a loading helper for command line config variables

func EnvLoader

func EnvLoader() BackingLoader

EnvLoader is a loading helper for Env{} config variables

func IniLoader

func IniLoader(filename string) BackingLoader

IniLoader is a helper for loading from Ini files

func MemLoader

func MemLoader() BackingLoader

MemLoader is a helper for loading a memory conf

type BackingLoaderFunc

type BackingLoaderFunc func() (Reader, error)

BackingLoaderFunc can wrap a function to turn it into a BackingLoader

func (BackingLoaderFunc) Get

func (f BackingLoaderFunc) Get() (Reader, error)

Get a Reader for Config, or an error if the Reader cannot be loaded

type Bool

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

Bool is a Boolean type config inside a Config. It uses strconv.ParseBool to parse the conf contents as either true for false

func (*Bool) Get

func (s *Bool) Get() bool

Get the boolean in this config variable

func (*Bool) Watch

func (s *Bool) Watch(watch BoolWatch)

Watch adds a watch for changes to this structure

type BoolWatch

type BoolWatch func(str *Bool, oldValue bool)

BoolWatch is executed if registered on a Bool variable any time the Bool contents change

type DistInfo

type DistInfo struct {
	File         string      `json:"file"`
	Line         int         `json:"line"`
	DefaultValue interface{} `json:"default_value"`
	DistType     DistType    `json:"dist_type"`
}

DistInfo is useful to unmarshal/marshal the Info expvar

type DistType

type DistType int

DistType is used to type each of the DistInfos

const (
	// StrType is type Str
	StrType DistType = iota
	// BoolType is type Bool
	BoolType
	// FloatType is type Float
	FloatType
	// DurationType is type Duration
	DurationType
	// IntType is type Int
	IntType
)

type Distconf

type Distconf struct {
	Logger log.Logger
	// contains filtered or unexported fields
}

Distconf gets configuration data from the first backing that has it

func FromLoaders

func FromLoaders(loaders []BackingLoader) *Distconf

FromLoaders creates a Config from an array of loaders, only using loaders that don't load with error

func New

func New(readers []Reader) *Distconf

New creates a Distconf from a list of backing readers

func (*Distconf) Bool

func (c *Distconf) Bool(key string, defaultVal bool) *Bool

Bool object that can be referenced to get boolean values from a backing config

func (*Distconf) Close

func (c *Distconf) Close()

Close this config framework's readers. Config variable results are undefined after this call.

func (*Distconf) Duration

func (c *Distconf) Duration(key string, defaultVal time.Duration) *Duration

Duration returns a duration object that calls ParseDuration() on the given key

func (*Distconf) Float

func (c *Distconf) Float(key string, defaultVal float64) *Float

Float object that can be referenced to get float values from a backing config

func (*Distconf) Info

func (c *Distconf) Info() expvar.Var

Info returns an expvar variable that shows the information for all configuration variables. Information consist of file, line, default value and type of variable.

func (*Distconf) Int

func (c *Distconf) Int(key string, defaultVal int64) *Int

Int object that can be referenced to get integer values from a backing config

func (*Distconf) Str

func (c *Distconf) Str(key string, defaultVal string) *Str

Str object that can be referenced to get string values from a backing config

func (*Distconf) Var

func (c *Distconf) Var() expvar.Var

Var returns an expvar variable that shows all the current configuration variables and their current value

type Duration

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

Duration is a duration type config inside a Config.

func (*Duration) Get

func (s *Duration) Get() time.Duration

Get the string in this config variable

func (*Duration) Watch

func (s *Duration) Watch(watch DurationWatch)

Watch adds a watch for changes to this structure

type DurationWatch

type DurationWatch func(duration *Duration, oldValue time.Duration)

DurationWatch is executed if registered on a Duration variable any time the contents change

type Dynamic

type Dynamic interface {
	Watch(key string, callback backingCallbackFunction) error
}

A Dynamic config can change what it thinks a value is over time.

type Float

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

Float is an float type config inside a Config.

func (*Float) Get

func (c *Float) Get() float64

Get the float in this config variable

func (*Float) Watch

func (c *Float) Watch(watch FloatWatch)

Watch for changes to this variable.

type FloatWatch

type FloatWatch func(float *Float, oldValue float64)

FloatWatch is called on any changes to a register integer config variable

type Int

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

Int is an integer type config inside a Config.

func (*Int) Get

func (c *Int) Get() int64

Get the integer in this config variable

func (*Int) Watch

func (c *Int) Watch(watch IntWatch)

Watch for changes to this variable.

type IntWatch

type IntWatch func(str *Int, oldValue int64)

IntWatch is called on any changes to a register integer config variable

type Reader

type Reader interface {
	Get(key string) ([]byte, error)
	Close()
}

Reader can get a []byte value for a config key

func Cmd

func Cmd(prefix string) Reader

Cmd creates a backing reader that reads config varaibles from command line parameters with a prefix

func Env

func Env() Reader

Env creates a backing config reader that reads properties from environment variables

func Ini

func Ini(filename string) (Reader, error)

Ini creates a backing config reader that reads properties from an Ini file

type ReaderWriter

type ReaderWriter interface {
	Reader
	Writer
}

A ReaderWriter can both read and write configuration information

func Mem

func Mem() ReaderWriter

Mem creates a memory config

func Zk

func Zk(zkConnector ZkConnector, conf *ZkConfig) (ReaderWriter, error)

Zk creates a zookeeper readable backing

type Str

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

Str is a string type config inside a Config.

func (*Str) Get

func (s *Str) Get() string

Get the string in this config variable

func (*Str) Watch

func (s *Str) Watch(watch StrWatch)

Watch adds a watch for changes to this structure

type StrWatch

type StrWatch func(str *Str, oldValue string)

StrWatch is executed if registered on a Str variable any time the Str contents change

type Writer

type Writer interface {
	Write(key string, value []byte) error
}

Writer can modify Config properties

type ZkConfig

type ZkConfig struct {
	Logger log.Logger
}

ZkConfig configures optional settings about a zk distconf

type ZkConn

type ZkConn interface {
	Exists(path string) (bool, *zk.Stat, error)
	Get(path string) ([]byte, *zk.Stat, error)
	GetW(path string) ([]byte, *zk.Stat, <-chan zk.Event, error)
	Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error)
	Set(path string, data []byte, version int32) (*zk.Stat, error)
	ExistsW(path string) (bool, *zk.Stat, <-chan zk.Event, error)
	ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error)
	Delete(path string, version int32) error
	Close()
}

ZkConn does zookeeper connections

type ZkConnector

type ZkConnector interface {
	Connect() (ZkConn, <-chan zk.Event, error)
}

ZkConnector creates zk connections for distconf

type ZkConnectorFunc

type ZkConnectorFunc func() (ZkConn, <-chan zk.Event, error)

ZkConnectorFunc wraps a dumb function to help you get a ZkConnector

func (ZkConnectorFunc) Connect

func (z ZkConnectorFunc) Connect() (ZkConn, <-chan zk.Event, error)

Connect to Zk by calling itself()

Jump to

Keyboard shortcuts

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