> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components/openfeature-providers/go-sdk.md).

# OpenFeature Provider for Go SDK

Integrate your Go applications with Harness FME using the Go OpenFeature Provider, a standardized, vendor-agnostic feature flagging API. This provider implements the OpenFeature specification and bridges the OpenFeature SDK with the Harness FME Go SDK.

This page walks you through installing, configuring, and using the Go OpenFeature provider to evaluate feature flags in your Go applications.

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Before you begin, ensure you have the following:

* A valid [Harness FME SDK key](/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components.md#api-keys) for your project
* A Go environment running version 1.21 or later
* Access to your Go module configuration (`go.mod`)

### Version compatibility <a href="#version-compatibility" id="version-compatibility"></a>

| Component                                          | Minimum Version |
| -------------------------------------------------- | --------------- |
| Go                                                 | 1.21+           |
| `github.com/splitio/split-openfeature-provider-go` | ≥ 2.0.0         |
| OpenFeature Go SDK                                 | ≥ 1.0.0         |

### Install the provider and dependencies <a href="#install-the-provider-and-dependencies" id="install-the-provider-and-dependencies"></a>

Add the Harness FME OpenFeature provider to your Go module.

```bash
go get github.com/splitio/split-openfeature-provider-go
```

### Initialize the provider <a href="#initialize-the-provider" id="initialize-the-provider"></a>

You can instantiate and register the provider using your Harness FME SDK key.

```go
import (
    "github.com/open-feature/go-sdk/openfeature"
    splitProvider "github.com/splitio/split-openfeature-provider-go"
)

provider, err := splitProvider.NewProviderSimple("YOUR_SDK_API_KEY")
if err != nil {
    // Provider creation error
}
openfeature.SetProviderAndWait(provider)
```

Alternatively, if you want more control or need [advanced initialization](/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components/server-side-sdks/go-sdk.md#configuration), you can create a `SplitClient` and provide it directly:

```go
import (
    "github.com/open-feature/go-sdk/openfeature"
    "github.com/splitio/go-client/v6/splitio/client"
    "github.com/splitio/go-client/v6/splitio/conf"
    splitProvider "github.com/splitio/split-openfeature-provider-go"
)

cfg := conf.Default()
factory, err := client.NewSplitFactory("YOUR_SDK_API_KEY", cfg)
if err != nil {
    // SDK initialization error
}

splitClient := factory.Client()
if err := splitClient.BlockUntilReady(10); err != nil {
    // SDK timeout error
}

provider, err := splitProvider.NewProvider(splitClient)
if err != nil {
    // Provider creation error
}
_ = openfeature.SetProviderAndWait(provider)
```

### Construct an evaluation context <a href="#construct-an-evaluation-context" id="construct-an-evaluation-context"></a>

Provide an evaluation context with a targeting key to evaluate flags. The evaluation context passes targeting information such as user IDs, email addresses, or plan types for flag targeting.

For example:

```go
import "context"

client := openfeature.NewClient("CLIENT_NAME")
ctx := context.Background()

evaluationContext := openfeature.NewEvaluationContext("TARGETING_KEY", nil)
boolValue, err := client.BooleanValue(ctx, "boolFlag", false, evaluationContext)
```

If the same targeting key is reused across evaluations, set the context at the client level:

```go
evaluationContext := openfeature.NewEvaluationContext("TARGETING_KEY", nil)
client.SetEvaluationContext(evaluationContext)
```

Or globally:

```go
evaluationContext := openfeature.NewEvaluationContext("TARGETING_KEY", nil)
openfeature.SetEvaluationContext(evaluationContext)
```

Once the context is set at the client or API level, you don't need to provide it for each evaluation.

### Evaluate with details <a href="#evaluate-with-details" id="evaluate-with-details"></a>

Use the `*ValueDetails` APIs to get flag values and metadata (such as variant, reason, error code, and configuration). The FME treatment configuration is returned as a raw JSON string under `FlagMetadata["config"]`.

For example:

```go
details, err := client.StringValueDetails(ctx, "my-flag", "fallback", evalCtx)
if err == nil && details.FlagMetadata != nil {
    if config, ok := details.FlagMetadata["config"].(string); ok {
        // config holds the Split treatment config
    }
}
```

### Track events <a href="#track-events" id="track-events"></a>

The Harness FME OpenFeature provider supports tracking user actions or conversion events directly from your Go application.

To enable event tracking with `Track(ctx, eventName, evalCtx, details)`, your evaluation context must include the following:

* A non-blank targeting key on the `EvaluationContext`
* A [`trafficType`](/feature-management-experimentation/management-and-administration/traffic-types.md) attribute (for example, `"user"` or `"account"`)
* A non-blank event name

Optionally, you can include a numeric value and additional event properties using `openfeature.NewTrackingEventDetails(value)` and `.Add(key, value)`. For more information, see [Sending Events](/feature-management-experimentation/management-and-administration/api-best-practices/events.md#event-record-fields).

For example:

```go
evalCtx := openfeature.NewEvaluationContext("user-123", map[string]any{"trafficType": "user"})

details := openfeature.NewTrackingEventDetails(19.99).
    Add("plan", "pro").
    Add("coupon", "WELCOME10")

client.Track(ctx, "checkout.completed", evalCtx, details)
```

For more information, go to the [Harness FME Go OpenFeature Provider GitHub repository](https://github.com/splitio/split-openfeature-provider-go).
