-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.go
93 lines (75 loc) · 2.12 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package config
import (
"context"
"time"
"github.com/pkg/errors"
)
var (
// ErrNoValue indicates no value was set for the config
ErrNoValue = errors.New("config: no value set")
// ErrShutdown indicates the use of a Config after calling Shutdown
ErrShutdown = errors.New("config: shutdown")
)
// Config is an interface for getting a configuration value
type Config interface {
// Get returns the latest config value
Get(ctx context.Context) (interface{}, error)
// Shutdown signals the config to stop all underlying resources
Shutdown()
}
// NoopConfig is a config that does not yield any values.
var NoopConfig = &noopConfig{}
type noopConfig struct{}
func (*noopConfig) Get(_ context.Context) (interface{}, error) {
return nil, ErrNoValue
}
func (*noopConfig) Shutdown() {
}
// Bool provides a boolean typed config.Config.
type Bool interface {
Get(ctx context.Context) bool
GetSafe(ctx context.Context) (bool, error)
Shutdown()
}
// Bytes provides a bytes typed config.Config.
type Bytes interface {
Get(ctx context.Context) []byte
GetSafe(ctx context.Context) ([]byte, error)
Shutdown()
}
// Duration provides a time.Duration typed config.Config.
type Duration interface {
Get(ctx context.Context) time.Duration
GetSafe(ctx context.Context) (time.Duration, error)
Shutdown()
}
// Encrypted provides an encrypted bytes typed config.Config.
type Encrypted interface {
Get(ctx context.Context) []byte
GetSafe(ctx context.Context) ([]byte, error)
Shutdown()
}
// Float64 provides a float64 typed config.Config.
type Float64 interface {
Get(ctx context.Context) float64
GetSafe(ctx context.Context) (float64, error)
Shutdown()
}
// Int64 provides an int64 typed config.Config.
type Int64 interface {
Get(ctx context.Context) int64
GetSafe(ctx context.Context) (int64, error)
Shutdown()
}
// Uint64 provides a uint64 typed config.Config.
type Uint64 interface {
Get(ctx context.Context) uint64
GetSafe(ctx context.Context) (uint64, error)
Shutdown()
}
// String provides a string typed config.Config.
type String interface {
Get(ctx context.Context) string
GetSafe(ctx context.Context) (string, error)
Shutdown()
}