-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
56 lines (48 loc) · 1.23 KB
/
default.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
package sfsdk
import (
"errors"
"github.com/simpleflags/evaluation"
"github.com/simpleflags/golang-server-sdk/client"
"github.com/simpleflags/golang-server-sdk/connector"
"github.com/simpleflags/golang-server-sdk/log"
"sync"
)
var (
once sync.Once
defaultClient client.Client
)
func Initialize(apiKey string, options ...client.ConfigOption) error {
var err error
once.Do(func() {
defaultClient, err = client.New(apiKey, options...)
})
return err
}
func InitWithConnector(connector connector.Connector, options ...client.ConfigOption) error {
var err error
once.Do(func() {
defaultClient, err = client.NewWithConnector(connector, options...)
})
return err
}
func WaitForInitialization() {
if defaultClient != nil {
defaultClient.WaitForInitialization()
}
}
func Evaluate(feature string, target evaluation.Target) evaluation.Evaluation {
if defaultClient != nil {
return defaultClient.Evaluate(feature, target)
}
return evaluation.Evaluation{}
}
func Close() error {
if defaultClient != nil {
return defaultClient.Close()
}
return errors.New("defaultClient was not initialized")
}
// SetLogger sets the default logger to be used by this package
func SetLogger(logger log.Logger) {
log.SetLogger(logger)
}