-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathunleash.go
More file actions
137 lines (115 loc) · 4 KB
/
unleash.go
File metadata and controls
137 lines (115 loc) · 4 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package unleash
import "github.com/Unleash/unleash-go-sdk/v6/api"
var defaultClient *Client
// ErrorListener defines an interface that be implemented in order to receive
// errors and warnings from the client.
type ErrorListener interface {
// OnError is called whenever the client experiences an error.
OnError(error)
// OnWarning is called whenever the client experiences a warning.
OnWarning(error)
}
// MetricListener defines an interface that can be implemented in order to receive
// events that are relevant to sending metrics.
type MetricListener interface {
// OnCount is called whenever the specified feature is queried.
OnCount(string, bool)
// OnSent is called whenever the server has successfully sent metrics to the server.
OnSent(MetricsData)
// OnRegistered is called whenever the client has successfully registered with the metrics server.
OnRegistered(ClientData)
}
// RepositoryListener defines an interface that can be implemented in order to receive events that are relevant to
// the feature toggle repository.
type RepositoryListener interface {
// OnReady is called when the client has loaded the feature toggles from
// the Unleash server.
OnReady()
// OnUpdate is called each time the client has loaded the features toggles from
// the Unleash server after the initial request.
OnUpdate()
}
// ImpressionListener defines an interface that can be implemented in order to receive
// impression events when a feature with impression data is evaluated.
type ImpressionListener interface {
// OnImpression is called whenever a feature with impression data is evaluated.
OnImpression(ImpressionEvent)
}
// IsEnabled queries the default client whether or not the specified feature is enabled or not.
func IsEnabled(feature string, options FeatureOptions) bool {
if defaultClient == nil {
return handleFallback(options.FallbackFunc, options.Fallback, feature, &options.Ctx).Enabled
}
return defaultClient.IsEnabled(feature, options)
}
// Initialize will specify the options to be used by the default client.
func Initialize(options ...ConfigOption) (err error) {
defaultClient, err = NewClient(options...)
return err
}
func GetVariant(feature string, options VariantOptions) *api.Variant {
if defaultClient == nil {
return api.GetDefaultVariant()
}
return defaultClient.GetVariant(feature, options)
}
// Close will close the default client.
func Close() error {
if defaultClient == nil {
return nil
}
return defaultClient.Close()
}
// WaitForReady will block until the default client is ready or return immediately.
func WaitForReady() {
defaultClient.WaitForReady()
}
// DefineCounter registers a counter metric for impact metrics reporting.
func DefineCounter(name, help string) {
if defaultClient == nil {
return
}
defaultClient.DefineCounter(name, help)
}
// IncrementCounter increments a previously defined counter metric.
func IncrementCounter(name string) {
if defaultClient == nil {
return
}
defaultClient.IncrementCounter(name)
}
// IncrementCounterBy increments a previously defined counter metric by a specified value.
func IncrementCounterBy(name string, value int64) {
if defaultClient == nil {
return
}
defaultClient.IncrementCounterBy(name, value)
}
// DefineGauge registers a gauge metric for impact metrics reporting.
func DefineGauge(name, help string) {
if defaultClient == nil {
return
}
defaultClient.DefineGauge(name, help)
}
// UpdateGauge updates the value for a previously defined gauge metric.
func UpdateGauge(name string, value float64) {
if defaultClient == nil {
return
}
defaultClient.UpdateGauge(name, value)
}
// DefineHistogram registers a histogram metric for impact metrics reporting.
func DefineHistogram(name, help string, buckets ...float64) {
if defaultClient == nil {
return
}
defaultClient.DefineHistogram(name, help, buckets...)
}
// ObserveHistogram records a value in a previously defined histogram metric.
func ObserveHistogram(name string, value float64) {
if defaultClient == nil {
return
}
defaultClient.ObserveHistogram(name, value)
}