forked from thomaspoignant/go-feature-flag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
90 lines (73 loc) · 3.29 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
package ffclient
import (
"context"
"errors"
"log"
"time"
"github.com/thomaspoignant/go-feature-flag/retriever"
"github.com/thomaspoignant/go-feature-flag/notifier"
)
// Config is the configuration of go-feature-flag.
// You should also have a retriever to specify where to read the flags file.
type Config struct {
// PollingInterval (optional) Poll every X time
// The minimum possible is 1 second
// Default: 60 seconds
PollingInterval time.Duration
// EnablePollingJitter (optional) set to true if you want to avoid having true periodicity when
// retrieving your flags. It is useful to avoid having spike on your flag configuration storage
// in case your application is starting multiple instance at the same time.
// We ensure a deviation that is maximum + or - 10% of your polling interval.
// Default: false
EnablePollingJitter bool
// Logger (optional) logger use by the library
// Default: No log
Logger *log.Logger
// Context (optional) used to call other services (HTTP, S3 ...)
// Default: context.Background()
Context context.Context
// Environment (optional), can be checked in feature flag rules
// Default: ""
Environment string
// Retriever is the component in charge to retrieve your flag file
Retriever retriever.Retriever
// Retrievers is the list of components in charge to retrieving your flag files.
// We are dealing with config files in order, if you have the same flag name in multiple files it will be override
// based of the order of the retrievers in the slice.
//
// Note: If both Retriever and Retrievers are set, we will start by calling the Retriever and,
// after we will use the order of Retrievers.
Retrievers []retriever.Retriever
// Notifiers (optional) is the list of notifiers called when a flag change
Notifiers []notifier.Notifier
// FileFormat (optional) is the format of the file to retrieve (available YAML, TOML and JSON)
// Default: YAML
FileFormat string
// DataExporter (optional) is the configuration where we store how we should output the flags variations results
DataExporter DataExporter
// StartWithRetrieverError (optional) If true, the SDK will start even if we did not get any flags from the retriever.
// It will serve only default values until all the retrievers returns the flags.
// The init method will not return any error if the flag file is unreachable.
// Default: false
StartWithRetrieverError bool
// Offline (optional) If true, the SDK will not try to retrieve the flag file and will not export any data.
// No notification will be sent neither.
// Default: false
Offline bool
}
// GetRetrievers returns a retriever.Retriever configure with the retriever available in the config.
func (c *Config) GetRetrievers() ([]retriever.Retriever, error) {
if c.Retriever == nil && (c.Retrievers == nil || len(c.Retrievers) == 0) {
return nil, errors.New("no retriever in the configuration, impossible to get the flags")
}
retrievers := make([]retriever.Retriever, 0)
// If we have both Retriever and Retrievers fields configured we are 1st looking at what is available
// in Retriever before looking at what is in Retrievers.
if c.Retriever != nil {
retrievers = append(retrievers, c.Retriever)
}
if c.Retrievers != nil && len(c.Retrievers) > 0 {
retrievers = append(retrievers, c.Retrievers...)
}
return retrievers, nil
}