Skip to main content
Version: v1.31.0

GO SDK usage

GO Version

Install dependencies

The first things we will do is install the Open Feature SDK and the GO Feature Flag provider.

go get
go get

Initialize your Open Feature provider

Despite other providers, this GO provider can be used with the relay proxy or standalone using the GO Feature Flag module.

Using the relay proxy

If you want to use the provider with the relay proxy you should set the field Endpoint in the options. By default it will use a default HTTPClient with a timeout configured at 10000 milliseconds. You can change this configuration by providing your own configuration of the HTTPClient.


options := gofeatureflag.ProviderOptions{
Endpoint: "http://localhost:1031",
HTTPClient: &http.Client{
Timeout: 1 * time.Second,
provider, _ := gofeatureflag.NewProvider(options)

Using the GO module (standalone version)

If you want to use the provider in standalone mode using the GO module, you should set the field GOFeatureFlagConfig in the options.

You can check the GO Feature Flag documentation website to look how to configure the GO module.


options := gofeatureflag.ProviderOptions{
GOFeatureFlagConfig: &ffclient.Config{
PollingInterval: 10 * time.Second,
Context: context.Background(),
Retriever: &fileretriever.Retriever{
Path: "../testutils/module/flags.yaml",
provider, _ := gofeatureflag.NewProvider(options)

Initialize your Open Feature client

To evaluate the flags you need to have an Open Feature configured in you app. This code block shows you how you can create a client that you can use in your application.

import (
// ...
gofeatureflag ""
of ""

// ...

options := gofeatureflag.ProviderOptions{
Endpoint: "http://localhost:1031",
provider, err := gofeatureflag.NewProvider(options)
client := of.NewClient("my-app")

Evaluate your flag

This code block explain how you can create an EvaluationContext and use it to evaluate your flag.

In this example we are evaluating a boolean flag, but other types are also available.

Refer to the Open Feature documentation to know more about it.

evaluationCtx := of.NewEvaluationContext(
"firstname", "john",
"lastname", "doe",
"email", "",
"admin", true,
"anonymous", false,
adminFlag, _ := client.BoolValue(context.TODO(), "flag-only-for-admin", false, evaluationCtx)
if adminFlag {
// flag "flag-only-for-admin" is true for the user
} else {
// flag "flag-only-for-admin" is false for the user

Contribute to the provider

You can find the source of the provider in the open-feature/go-sdk-contrib repository.

Get the latest GO Feature Flag updates