GO
The GO Feature Flag provider connects the OpenFeature Go SDK to a GO Feature Flag relay-proxy.
It supports two evaluation modes:
INPROCESSis the default. The provider fetches flag configuration from the relay-proxy, evaluates flags locally with the GO Feature Flag core library, and keeps the local configuration fresh by polling for updates.REMOTEdelegates every evaluation to the relay-proxy via OFREP: the relay-proxy remains the single source of truth, no local configuration or polling is needed, and flag changes take effect immediately on the server.
Install dependencies
Install the provider and the OpenFeature Go SDK:
go get github.com/open-feature/go-sdk-contrib/providers/go-feature-flag
Choose an evaluation mode
| Mode | Description | When to use it |
|---|---|---|
INPROCESS | Fetch configuration once, evaluate locally, poll for configuration changes. | Default choice for lower evaluation latency and the new 1.x.x behavior. |
REMOTE | A request is sent to the relay-proxy for each evaluation. | Single source of truth on the server, no local config or polling; flag changes apply immediately. |
Initialize your provider
INPROCESS is the default, so setting EvaluationType is optional, use REMOTE when you want to preserve the old remote-evaluation behavior while upgrading.
- In Process
- Remote
import (
"context"
gofeatureflag "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg"
)
ctx := context.Background()
provider, err := gofeatureflag.NewProviderWithContext(ctx, gofeatureflag.ProviderOptions{
Endpoint: "http://localhost:1031",
EvaluationType: gofeatureflag.EvaluationTypeInProcess, // this line is optional because inprocess is the default
})
if err != nil {
// handle the error
}
import (
"context"
gofeatureflag "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg"
)
ctx := context.Background()
provider, err := gofeatureflag.NewProviderWithContext(ctx, gofeatureflag.ProviderOptions{
Endpoint: "http://localhost:1031",
EvaluationType: gofeatureflag.EvaluationTypeRemote,
})
if err != nil {
// handle the error
}
Initialize your OpenFeature client
Register the provider in the OpenFeature SDK and then create a client:
import (
"context"
gofeatureflag "github.com/open-feature/go-sdk-contrib/providers/go-feature-flag/pkg"
of "github.com/open-feature/go-sdk/openfeature"
)
ctx := context.Background()
provider, err := gofeatureflag.NewProviderWithContext(ctx, gofeatureflag.ProviderOptions{
Endpoint: "http://localhost:1031",
})
if err != nil {
// handle the error
}
if err := of.SetProviderAndWait(provider); err != nil {
// handle the error
}
client := of.NewClient("my-app")
Evaluate a flag
Create an EvaluationContext and use the OpenFeature client as usual.
In this example we evaluate a boolean flag, but the provider also supports string, integer, float, and object evaluations.
See the OpenFeature evaluation API documentation for the full API surface.
evaluationCtx := of.NewEvaluationContext(
"1d1b9238-2591-4a47-94cf-d2bc080892f1",
map[string]any{
"firstname": "john",
"lastname": "doe",
"email": "john.doe@gofeatureflag.org",
"admin": true,
"anonymous": false,
},
)
adminFlag, err := client.BooleanValue(context.TODO(), "flag-only-for-admin", false, evaluationCtx)
if err != nil {
// handle the error
}
if adminFlag {
// flag "flag-only-for-admin" evaluated to true
} else {
// flag "flag-only-for-admin" evaluated to false
}
Provider options
Endpoint is required. The other options are optional.
| Option | Description |
|---|---|
Endpoint | Base URL of the GO Feature Flag relay-proxy (e.g. http://localhost:1031). Required. |
HTTPClient | Custom HTTP client. If omitted, the provider uses a default client with a 10-second timeout. |
APIKey | API key sent as X-API-Key. |
Headers | Extra headers added to provider HTTP requests. Useful for custom auth headers such as Authorization. |
ExporterMetadata | Metadata attached to exported evaluation and tracking events. |
EvaluationType | Selects INPROCESS or REMOTE. Default is INPROCESS. |
FlagChangePollingInterval | Poll interval used in INPROCESS mode to refresh the local flag configuration. |
DataCollectorMaxEventStored | Maximum number of buffered events before the collector flushes the queue on a subsequent add. |
DataCollectorCollectInterval | Interval used to send buffered events to the relay-proxy data collector. |
DataCollectorDisabled | Disables event collection and tracking export. |
DataCollectorBaseURL | Overrides the base URL used only for the data collector endpoint. |
Logger | Custom slog.Logger used by the provider. |
Tracking and event collection
Flag usage events (automatic)
In INPROCESS mode, the provider automatically collects a flag evaluation event every time a flag is evaluated. These events are batched in memory and flushed to the relay-proxy data collector endpoint (POST /v1/data/collector) periodically or when the buffer is full.
Each event records:
- The flag key and the variation that was served
- The user key and whether the user was anonymous
- The resolved value and whether the SDK default was returned
- A creation timestamp
The flush is also triggered on provider shutdown so no buffered events are lost.