config

package
v0.2.1-0...-d3ae3b1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UpdateEvent corresponds to a normal configuration udpate.
	UpdateEvent = "update"
	// RevertEvent corresponds to a configuration rollback in case of errors.
	RevertEvent = "rollback"
)
View Source
const (
	// MainModule is the default parent for all configuration.
	MainModule = "main"
)

Variables

This section is empty.

Functions

func Describe

func Describe(names ...string)

Describe provides help about configuration of the given modules.

func Print

func Print(printfn func(string, ...interface{}))

Print prints the current configuration, using the given function or fmt.Printf.

func SetConfig

func SetConfig(cfg map[string]string) error

SetConfig updates the configuration using data from an external source.

func SetConfigFromFile

func SetConfigFromFile(path string) error

SetConfigFromFile updates the configuration from the given file.

func SetLogger

func SetLogger(logger Logger)

SetLogger sets our logger.

Types

type Data

type Data map[string]interface{}

Data is our internal representation of configuration data.

func DataFromFile

func DataFromFile(path string) (Data, error)

DataFromFile unmarshals the content of the given file into configuration data.

func DataFromObject

func DataFromObject(obj interface{}) (Data, error)

DataFromObject remarshals the given object into configuration data.

func DataFromStringMap

func DataFromStringMap(smap map[string]string) (Data, error)

DataFromStringMap remarshals the given map into configuration data.

func GetConfig

func GetConfig() (Data, error)

GetConfig returns the current configuration.

func (Data) Print

func (d Data) Print(fn func(string, ...interface{}))

Print prints the configuration data using the given function or fmt.Printf.

func (Data) String

func (d Data) String() string

String returns configuration data as a string.

type Event

type Event string

Event describes what triggered an invocation of a configuration notification callback.

type GetConfigFn

type GetConfigFn func() interface{}

GetConfigFn is used to query a module for its default configuration.

type Logger

type Logger struct {
	DebugEnabled func() bool
	Debug        func(string, ...interface{})
	Info         func(string, ...interface{})
	Warning      func(string, ...interface{})
	Error        func(string, ...interface{})
	Fatal        func(string, ...interface{})
	Panic        func(string, ...interface{})
	Block        func(func(string, ...interface{}), string, string, ...interface{})
}

Logger is our set of logging functions.

type Module

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

Module is a logical unit of configuration, declared using Declare().

func GetModule

func GetModule(path string) *Module

GetModule looks up the module for the given path, implicitly creating it if necessary.

func Register

func Register(path, description string, ptr interface{}, getfn GetConfigFn, opts ...Option) *Module

Register registers a unit of configuration data to be handled by this package.

func (*Module) AddNotify

func (m *Module) AddNotify(fn NotifyFn) error

AddNotify attaches the given update notification callback to the module.

type NotifyFn

type NotifyFn func(Event, Source) error

NotifyFn is used to notify a module about configuration changes.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is the generic interface for any option applicable to a Module or Config.

func WithNotify

func WithNotify(fn NotifyFn) Option

WithNotify specifies a notification function to be called after configuration updates.

func WithoutDataValidation

func WithoutDataValidation() Option

WithoutDataValidation specifies that data passed to this module should not be validated.

type Source

type Source string

Source describes where configuration is originated from.

const (
	// ConfigFile is a YAML/JSON file configuration source.
	ConfigFile Source = "configuration file"
	// ConfigExternal is an external configuration source, for instance a node agent.
	ConfigExternal Source = "external configuration"
	// ConfigBackup is a backup of the previous configuration.
	ConfigBackup Source = "backed up configuration"
)

Jump to

Keyboard shortcuts

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