Skip to content

Quickstart: Go

Evaluate a flag in a Go backend with OpenFeature and EZGH's Go provider.

Updated View as Markdown

1. A flag and a server key

ezgh flags envs create production
ezgh flags create new-checkout --name "New checkout"
ezgh flags toggle new-checkout --env production --on
export EZGH_FLAGS_SDK_KEY=$(ezgh flags keys create --env production --kind server --name quickstart)

2. Install

go get github.com/ezgamehost/flags-provider-go@v0.1.0 github.com/open-feature/go-sdk

3. Evaluate

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	ezghflags "github.com/ezgamehost/flags-provider-go"
	"github.com/open-feature/go-sdk/openfeature"
)

func main() {
	provider := ezghflags.New(os.Getenv("EZGH_FLAGS_SDK_KEY"))
	if err := openfeature.SetProviderAndWait(provider); err != nil {
		log.Fatal(err)
	}
	defer openfeature.Shutdown()

	flags := openfeature.NewClient("checkout")
	evalCtx := openfeature.NewEvaluationContext("user-1842", map[string]any{"plan": "pro"})
	details, err := flags.BooleanValueDetails(context.Background(), "new-checkout", false, evalCtx)
	if err != nil {
		log.Println(err)
	}
	fmt.Println(details.Value, details.Reason)
}

It prints true STATIC: turned on, a new boolean flag serves true to everyone. Change the flag’s targeting (Targeting) and a running process gets the change within seconds.

The provider downloads the environment’s flags and evaluates locally, follows a stream of changes, and keeps evaluating its last flags while disconnected. Options:

Option Does
ezghflags.WithEndpoint(url) Another data plane than https://flags.ezghcloud.com
ezghflags.WithHTTPClient(c) Your own *http.Client
ezghflags.WithBootstrapFile(path) Start from a file written by ezgh flags export
ezghflags.WithOffline() Use only the bootstrap file, with no network
Navigation

Type to search…

↑↓ navigate↵ selectEsc close