-
Notifications
You must be signed in to change notification settings - Fork 75
/
config.go
53 lines (44 loc) · 1.07 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Package config is an interface for dynamic configuration.
package config
import (
"context"
"time"
"github.com/micro/go-config/reader"
"github.com/micro/go-config/source"
)
// Config is an interface abstraction for dynamic configuration
type Config interface {
Close() error
Bytes() []byte
Get(path ...string) Value
Load(source ...source.Source) error
Watch(path ...string) (Watcher, error)
}
// Watcher is the config watcher
type Watcher interface {
Next() (Value, error)
Stop() error
}
// Value represents a value of any type
type Value interface {
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 {
Reader reader.Reader
Source []source.Source
// for alternative data
Context context.Context
}
type Option func(o *Options)
// NewConfig returns new config
func NewConfig(opts ...Option) Config {
return newConfig(opts...)
}