Project: GO Feature Flag (Observability and Analysis / Feature Flagging)
File: configuration.md

sidebar_position: 10 description: How to configure the GO module to use it directly in your code. `go-feature-flag` needs to be initialized to be used. During the initialization you must give a configuration object. is the only location where you can put the configuration. | Field | Description | ||| | `Retriever` | The configuration retriever you want to use to get your flag file<br/> See for the configuration details.<br /><br /> This field is optional if `Retrievers` is configured. | | `Retrievers` | `Retrievers` is exactly the same thing as `Retriever` but you can configure more than 1 source for your flags.<br/>All flags are retrieved in parallel, but we are applying them in the order you provided them (it means that a flag can be overridden by another flag). <br/>See for the configuration details. <br /><br /> This field is optional if `Retrievers` is configured. | | `Context` | (optional)<br/>The context used by the retriever.<br />Default: `context.Background()` | | `Environment` | <a name="option_environment"></a>(optional)<br/>The environment the app is running under, can be checked in feature flag rules.<br />Default: `""`<br/>Check to understand how to use this parameter. | | `DataExporter` | (optional)<br/>DataExporter defines how to export data on how your flags are used.<br/> see for more details. | | `FileFormat` | (optional)<br/>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.<br/>Default: `YAML` | | `Logger` | (optional)<br/>Logger used to log what `go-feature-flag` is doing.<br />If no logger is provided the module will not log anything.<br/>Default: No log | | `Notifiers` | (optional)<br/>List of notifiers to call when your flag file has been changed.<br/> See for more details. | | `PollingInterval` | (optional) Duration to wait before refreshing the flags.<br/>The minimum polling interval is 1 second.<br/>Default: 60 * time.Second | | `StartWithRetrieverError` | (optional) If true, the SDK will start even if we did not get any flags from the

It will serve only default values until the retriever returns the flags.<br/>The init method will not return any error if the flag file is unreachable.<br/>Default: false | | `Offline` | (optional) If true, the SDK will not try to retrieve the flag file and will not export any data. No notification will be send neither.<br/>Default: false | ```go ffclient.Init(ffclient.Config{ PollingInterval: 3 * time.Second, Logger: log.New(file, "/tmp/log", 0), Context: context.Background(), Environment: os.Getenv("MYAPP_ENV"), Retriever: &fileretriever.Retriever{Path: "testdata/flag-config.yaml"}, FileFormat: "yaml", Notifiers: []notifier.Notifier{ &webhooknotifier.Notifier{ 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: &file.Exporter{ OutputDir: "/output-data/", }, }, StartWithRetrieverError: false, }) ``` `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. 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 . ```go linenums="1" x, err := ffclient.New(Config{ Retriever: &httpretriever.Retriever{{URL: "http://example.com/flag-config.yaml",}}) defer x.Close() y, err := ffclient.New(Config{ Retriever: &httpretriever.Retriever{{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 , it is up to the user to keep track of the different instances. In some situations, you might want to stop making remote calls and fall back to default values for your feature flags. For example, if your software is both cloud-hosted and distributed to customers to run on-premise, it might make sense to fall back to defaults when running on-premise. You can do this by setting `Offline` mode in the client's Config.