2019-05-31 01:11:13 +03:00
|
|
|
// Package config is an interface for dynamic configuration.
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-12-04 02:28:45 +03:00
|
|
|
"errors"
|
|
|
|
)
|
2019-05-31 01:11:13 +03:00
|
|
|
|
2020-12-04 02:28:45 +03:00
|
|
|
var (
|
2020-12-08 00:38:37 +03:00
|
|
|
// DefaultConfig default config
|
2020-12-04 02:28:45 +03:00
|
|
|
DefaultConfig Config = NewConfig()
|
2019-05-31 01:11:13 +03:00
|
|
|
)
|
|
|
|
|
2020-08-29 18:08:21 +03:00
|
|
|
var (
|
2020-12-13 13:26:44 +03:00
|
|
|
// ErrCodecMissing is returned when codec needed and not specified
|
|
|
|
ErrCodecMissing = errors.New("codec missing")
|
2020-12-13 13:10:04 +03:00
|
|
|
// ErrInvalidStruct is returned when the target struct is invalid
|
|
|
|
ErrInvalidStruct = errors.New("invalid struct specified")
|
2020-12-04 02:28:45 +03:00
|
|
|
// ErrWatcherStopped is returned when source watcher has been stopped
|
|
|
|
ErrWatcherStopped = errors.New("watcher stopped")
|
2020-08-29 18:08:21 +03:00
|
|
|
)
|
|
|
|
|
2019-05-31 01:11:13 +03:00
|
|
|
// Config is an interface abstraction for dynamic configuration
|
|
|
|
type Config interface {
|
2020-03-12 21:13:03 +03:00
|
|
|
// Init the config
|
|
|
|
Init(opts ...Option) error
|
2020-03-31 19:13:21 +03:00
|
|
|
// Options in the config
|
|
|
|
Options() Options
|
2020-12-04 02:28:45 +03:00
|
|
|
// Load config from sources
|
|
|
|
Load(context.Context) error
|
|
|
|
// Save config to sources
|
|
|
|
Save(context.Context) error
|
2019-05-31 01:11:13 +03:00
|
|
|
// Watch a value for changes
|
2020-12-04 02:28:45 +03:00
|
|
|
// Watch(interface{}) (Watcher, error)
|
|
|
|
String() string
|
2019-05-31 01:11:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Watcher is the config watcher
|
2020-12-04 02:28:45 +03:00
|
|
|
//type Watcher interface {
|
|
|
|
// Next() (, error)
|
|
|
|
// Stop() error
|
|
|
|
//}
|