2019-05-30 23:11:13 +01:00
|
|
|
// Package config is an interface for dynamic configuration.
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-08-19 17:47:17 +03:00
|
|
|
"github.com/unistack-org/micro/v3/config/loader"
|
|
|
|
"github.com/unistack-org/micro/v3/config/reader"
|
|
|
|
"github.com/unistack-org/micro/v3/config/source"
|
2019-05-30 23:11:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is an interface abstraction for dynamic configuration
|
|
|
|
type Config interface {
|
|
|
|
// provide the reader.Values interface
|
|
|
|
reader.Values
|
2020-03-12 18:13:03 +00:00
|
|
|
// Init the config
|
|
|
|
Init(opts ...Option) error
|
2020-03-31 17:13:21 +01:00
|
|
|
// Options in the config
|
|
|
|
Options() Options
|
2019-05-30 23:11:13 +01:00
|
|
|
// Stop the config loader/watcher
|
|
|
|
Close() error
|
|
|
|
// Load config sources
|
|
|
|
Load(source ...source.Source) error
|
|
|
|
// Force a source changeset sync
|
|
|
|
Sync() error
|
|
|
|
// Watch a value for changes
|
|
|
|
Watch(path ...string) (Watcher, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watcher is the config watcher
|
|
|
|
type Watcher interface {
|
|
|
|
Next() (reader.Value, error)
|
|
|
|
Stop() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
Loader loader.Loader
|
|
|
|
Reader reader.Reader
|
|
|
|
Source []source.Source
|
|
|
|
|
|
|
|
// for alternative data
|
|
|
|
Context context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
// NewConfig returns new config
|
2020-01-19 16:31:02 +08:00
|
|
|
func NewConfig(opts ...Option) (Config, error) {
|
2019-05-30 23:11:13 +01:00
|
|
|
return newConfig(opts...)
|
|
|
|
}
|