Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoConfigFile = errors.New("no configuration file found")
Functions ¶
This section is empty.
Types ¶
type Aborter ¶
type Aborter interface {
Abort(error)
}
Aborter provides abort notification to spread.
type ConfigLoader ¶
type ConfigLoader interface { // Filename returns the file name which can then be watched by fsnotify. Filename() string // Load provides a new Configuration from the filename on demand. Otherwise, // it should produce an error. Load() (Configuration, error) }
ConfigLoader can load configuration on demand.
Notifier relies on the fact the configuration file is coming from a file in the operating system, and it uses fsnotify package to watch the file system.
type Configuration ¶
type Configuration any
Configuration holds applications' configuration.
It can be anything, as long as diff3 can handle it
type Control ¶
type Control struct {
// contains filtered or unexported fields
}
Control keeps track of the current and previous configurations, and a changelog.
func New ¶
func New(loader ConfigLoader, logger *slog.Logger) (*Control, error)
New returns a new Control object, or an error.
It needs a ConfigLoader for reading the configuration, and a logger for logging purposes. A new configuration is read immediately.
func (*Control) Config ¶
func (ctrl *Control) Config() Configuration
Config returns the current configuration. It needs to be casted to the final type.
func (*Control) IsChanged ¶
IsChanged confirms whether a certain portion of the struct has been changed.
Item name is the configuration key's name. Deep configurations use "." as a delimiter. Numbers represent keys of slices.
"*" can be used at the end of the string as a wildcard for any keys. For example, if "Database.Connection.Host" changes, the following wildcards will match: "*", "Database.*", "Database.Connection.*". Note: "*" matches full key, there's no substring matching.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier tells subsystems about configuration changes.
func NewNotifier ¶
NewNotifier returns a new notifier object.
func (*Notifier) Notify ¶
Notify sends configuration change notification to Updateable services.
This method should be called right after services and aborters registered. It sends notification to the configuration object itself too, if it implements Updateable.
func (*Notifier) RegisterAborters ¶
RegisterAborters adds Aborter services to the list of services handling abortions.
func (*Notifier) RegisterServices ¶
func (notif *Notifier) RegisterServices(svc ...Updateable)
RegisterServices adds Updateable services to the list of services to be notified.
func (*Notifier) Watch ¶
Watch starts configuration file watching for changes using fsnotify.
It handles modify and remove events. On removal, it tries to re-add the file to the watchlist immediately, and continues trying with an exponential backoff (starting with 1/2 seconds, with a multiplier of 1.5, backing off after 10 tries).
type Updateable ¶
type Updateable interface { // UpdateConfig is called by Notifier on configuration change. When a change // cannot be handled for some reason, the error initiates abort. UpdateConfig(context.Context, *Control) error }
Updateable enables objects to have their configurations updated.