|
2 | 2 | package config
|
3 | 3 |
|
4 | 4 | import (
|
5 |
| - "context" |
6 |
| - |
7 |
| - "github.com/micro/go-micro/v3/config/loader" |
8 |
| - "github.com/micro/go-micro/v3/config/reader" |
9 |
| - "github.com/micro/go-micro/v3/config/source" |
| 5 | + "time" |
10 | 6 | )
|
11 | 7 |
|
12 | 8 | // Config is an interface abstraction for dynamic configuration
|
13 | 9 | type Config interface {
|
14 |
| - // provide the reader.Values interface |
15 |
| - reader.Values |
16 |
| - // Init the config |
17 |
| - Init(opts ...Option) error |
18 |
| - // Options in the config |
19 |
| - Options() Options |
20 |
| - // Stop the config loader/watcher |
21 |
| - Close() error |
22 |
| - // Load config sources |
23 |
| - Load(source ...source.Source) error |
24 |
| - // Force a source changeset sync |
25 |
| - Sync() error |
26 |
| - // Watch a value for changes |
27 |
| - Watch(path ...string) (Watcher, error) |
| 10 | + Get(path string, options ...Option) Value |
| 11 | + Set(path string, val interface{}, options ...Option) |
| 12 | + Delete(path string, options ...Option) |
28 | 13 | }
|
29 | 14 |
|
30 |
| -// Watcher is the config watcher |
31 |
| -type Watcher interface { |
32 |
| - Next() (reader.Value, error) |
33 |
| - Stop() error |
| 15 | +// Value represents a value of any type |
| 16 | +type Value interface { |
| 17 | + Exists() bool |
| 18 | + Bool(def bool) bool |
| 19 | + Int(def int) int |
| 20 | + String(def string) string |
| 21 | + Float64(def float64) float64 |
| 22 | + Duration(def time.Duration) time.Duration |
| 23 | + StringSlice(def []string) []string |
| 24 | + StringMap(def map[string]string) map[string]string |
| 25 | + Scan(val interface{}) error |
| 26 | + Bytes() []byte |
34 | 27 | }
|
35 | 28 |
|
36 | 29 | type Options struct {
|
37 |
| - Loader loader.Loader |
38 |
| - Reader reader.Reader |
39 |
| - Source []source.Source |
40 |
| - |
41 |
| - // for alternative data |
42 |
| - Context context.Context |
| 30 | + // Is the value being read a secret? |
| 31 | + // If true, the Config will try to decode it with `SecretKey` |
| 32 | + Secret bool |
43 | 33 | }
|
44 | 34 |
|
| 35 | +// Option sets values in Options |
45 | 36 | type Option func(o *Options)
|
46 | 37 |
|
47 |
| -// NewConfig returns new config |
48 |
| -func NewConfig(opts ...Option) (Config, error) { |
49 |
| - return newConfig(opts...) |
| 38 | +func Secret(isSecret bool) Option { |
| 39 | + return func(o *Options) { |
| 40 | + o.Secret = isSecret |
| 41 | + } |
50 | 42 | }
|
0 commit comments