config

package module
v0.0.0-...-5411f85 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: BSD-3-Clause Imports: 14 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Applier

type Applier func(currentConfig Config, newConfig Config) error

Applier is a function type which will apply the new configuration

type Chan

type Chan chan Config

Chan is a channel within which pointers to a new configuration will be sent.

type Config

type Config interface {
	// DeepCopyConfig returns a copy of the current struct.
	DeepCopyConfig() Config
	// ConfigFile returns the path of the config file.
	ConfigFile() string
}

Config is an interface describing functions needed by this module.

type Logger

type Logger interface {
	Tracef(string, ...interface{})
	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
	Fatalf(string, ...interface{})
}

Logger is the interface that describes the logger used by this module. You can wrap any logger lib that you alreadey use in a struct that comply with this interface if your logger does not already implement this interface. For instance github.com/sirupsen/logrus is already compliant with this interface. You can lookup for testLogger in config_test.go to see an example of wrapping.

type Manager

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

Manager is a struct that stores configuration watchers and the chans used to broadcasts new configurations when configurations files are updated.

func GetManager

func GetManager(logger Logger) *Manager

GetManager returns the Manager that will give you access to all your configs.

func (*Manager) AddAppliers

func (m *Manager) AddAppliers(name interface{}, appliers ...Applier)

AddAppliers ...

func (*Manager) AddValidators

func (m *Manager) AddValidators(name interface{}, validators ...Validator)

AddValidators ...

func (*Manager) GetConfig

func (m *Manager) GetConfig(name interface{}) Config

GetConfig returns an existing configuration, nil otherwise.

func (*Manager) GetWatcher

func (m *Manager) GetWatcher(name interface{}) *watcher

GetWatcher returns an existing configuration, nil otherwise.

func (*Manager) MakeConfig

func (m *Manager) MakeConfig(ctx context.Context, name interface{}, config Config) error

MakeConfig creates a named configuration. If config.ConfigFile() returns anything but an empty string it will spawn a goroutine which will watch for changes in the file. The file does not have to exists, it can be created after the config has been created.

func (*Manager) NewConfigChan

func (m *Manager) NewConfigChan(name interface{}) Chan

NewConfigChan returns a channel that will be used to send new configurations when the configuration file associated to the Config has been updated.

type Validator

type Validator func(currentConfig Config, newConfig Config) []error

Validator is a function type which will ensure that the content of the config file is valid and can be applied

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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