Skip to main content
Version: v0.17.3

Configuration

go-feature-flag needs to be initialized to be used.
During the initialization you must give a ffclient.Config{} configuration object.

ffclient.Config{} is the only location where you can put the configuration.

Configuration fields

FieldDescription
RetrieverThe configuration retriever you want to use to get your flag file
see Store your flag file for the configuration details.
Context(optional)
The context used by the retriever.
Default: context.Background()
DataExporter(optional)
DataExporter defines how to export data on how your flags are used.
see export data section for more details.
FileFormat(optional)
Format of your configuration file. Available formats are yaml, toml and json, if you omit the field it will try to unmarshal the file as a yaml file.
Default: YAML
Logger(optional)
Logger used to log what go-feature-flag is doing.
If no logger is provided the module will not log anything.
Default: No log
Notifiers(optional)
List of notifiers to call when your flag file has changed.
see notifiers section for more details.
PollingInterval(optional) Duration to wait before refreshing the flags.
The minimum polling interval is 1 second.
Default: 60 * time.Second
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 the retriever returns the flags.
The init method will not return any error if the flag file is unreachable.
Default: false

Example

ffclient.Init(ffclient.Config{ 
PollingInterval: 3 * time.Second,
Logger: log.New(file, "/tmp/log", 0),
Context: context.Background(),
Retriever: &ffclient.FileRetriever{Path: "testdata/flag-config.yaml"},
FileFormat: "yaml",
Notifiers: []ffclient.NotifierConfig{
&ffclient.WebhookConfig{
EndpointURL: " https://example.com/hook",
Secret: "Secret",
Meta: map[string]string{
"app.name": "my app",
},
},
},
DataExporter: ffclient.DataExporter{
FlushInterval: 10 * time.Second,
MaxEventInMemory: 1000,
Exporter: &ffexporter.File{
OutputDir: "/output-data/",
},
},
StartWithRetrieverError: false,
})

Multiple configuration flag files

go-feature-flag comes ready to use out of the box by calling the Init function and, it will be available everywhere.
Since most applications will want to use a single central flag configuration, the package provides this. It is similar to a singleton.

In all the examples above, they demonstrate using go-feature-flag in its singleton style approach.

Working with multiple go-feature-flag

You can also create many go-feature-flag clients to use in your application.

Each will have its own unique set of configurations and flags. Each can read from a different config file and from different places.
All the functions that go-feature-flag package supports are mirrored as methods on a GoFeatureFlag.

Example

x, err := ffclient.New(Config{ Retriever: &ffclient.HTTPRetriever{{URL: "http://example.com/flag-config.yaml",}})
defer x.Close()

y, err := ffclient.New(Config{ Retriever: &ffclient.HTTPRetriever{{URL: "http://example.com/test2.yaml",}})
defer y.Close()

user := ffuser.NewUser("user-key")
x.BoolVariation("test-flag", user, false)
y.BoolVariation("test-flag", user, false)

// ...

When working with multiple GoFeatureFlag, it is up to the user to keep track of the different GoFeatureFlag instances.

Advanced configuration

Get the latest GO Feature Flag updates