Config interface change (#2010)
This commit is contained in:
@@ -2,49 +2,41 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/micro/go-micro/v3/config/loader"
|
||||
"github.com/micro/go-micro/v3/config/reader"
|
||||
"github.com/micro/go-micro/v3/config/source"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Config is an interface abstraction for dynamic configuration
|
||||
type Config interface {
|
||||
// provide the reader.Values interface
|
||||
reader.Values
|
||||
// Init the config
|
||||
Init(opts ...Option) error
|
||||
// Options in the config
|
||||
Options() Options
|
||||
// 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)
|
||||
Get(path string, options ...Option) Value
|
||||
Set(path string, val interface{}, options ...Option)
|
||||
Delete(path string, options ...Option)
|
||||
}
|
||||
|
||||
// Watcher is the config watcher
|
||||
type Watcher interface {
|
||||
Next() (reader.Value, error)
|
||||
Stop() error
|
||||
// Value represents a value of any type
|
||||
type Value interface {
|
||||
Exists() bool
|
||||
Bool(def bool) bool
|
||||
Int(def int) int
|
||||
String(def string) string
|
||||
Float64(def float64) float64
|
||||
Duration(def time.Duration) time.Duration
|
||||
StringSlice(def []string) []string
|
||||
StringMap(def map[string]string) map[string]string
|
||||
Scan(val interface{}) error
|
||||
Bytes() []byte
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
Loader loader.Loader
|
||||
Reader reader.Reader
|
||||
Source []source.Source
|
||||
|
||||
// for alternative data
|
||||
Context context.Context
|
||||
// Is the value being read a secret?
|
||||
// If true, the Config will try to decode it with `SecretKey`
|
||||
Secret bool
|
||||
}
|
||||
|
||||
// Option sets values in Options
|
||||
type Option func(o *Options)
|
||||
|
||||
// NewConfig returns new config
|
||||
func NewConfig(opts ...Option) (Config, error) {
|
||||
return newConfig(opts...)
|
||||
func Secret(isSecret bool) Option {
|
||||
return func(o *Options) {
|
||||
o.Secret = isSecret
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user