-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
61 lines (54 loc) · 1.91 KB
/
interface.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
54
55
56
57
58
59
60
61
// configio defines a generic interface for config management
package configio
import (
"context"
"io"
)
// Config defines the behavior of a type that can act as a config parameter
// Any such type should provide serialization methods and ability to get a key
type Config interface {
Key() string
Marshal() ([]byte, error)
Unmarshal(b []byte) error
}
// ConfigManagerWithWatch defines an interface to access config params
type ConfigManagerWithWatch interface {
// Unmarshal unmarshals into marshaler
Unmarshal(config Config) error
// Marshal marshals data in marshaler
Marshal(config Config) error
// Watch registers a callback function
Watch(name string, data interface{},
f func(ctx context.Context, data interface{}, err error) <-chan error) <-chan struct{}
io.Closer
}
// ConfigManager defines an interface to perform read/write on config params
type ConfigManager interface {
// Unmarshal unmarshals into marshaler
Unmarshal(config Config) error
// Marshal marshals data in marshaler
Marshal(config Config) error
io.Closer
}
// ConfigReader defines an interface to perform read operation on config params
type ConfigReader interface {
// Unmarshal unmarshals into marshaler
Unmarshal(config Config) error
io.Closer
}
// ConfigWriter defines an interface to perform write operation on config params
type ConfigWriter interface {
// Marshal marshals data in marshaler
Marshal(config Config) error
io.Closer
}
// ConfigWatcher defines an interface to perform a watch on config changes.
// Watch registers a function that gets executed on config changes.
// If an error occurs on function execution, the function is called again with that
// error passed in as an input argument and is removed from the registry
type ConfigWatcher interface {
// Watch registers a callback function
Watch(name string, data interface{},
f func(ctx context.Context, data interface{}, err error) <-chan error) <-chan struct{}
io.Closer
}