Skip to content

featureguards/featureguards-go

Repository files navigation

Go SDK for FeatureGuards

Go Reference

The official FeatureGuards Go client library.

Installation

Make sure your project is using Go Modules (it will have a go.mod file in its root if it already is):

go mod init

Then, reference featureguards-go/v2 in a Go program with import:

import (
	featureguards "github.com/featureguards/featureguards-go/v2"
)

Run any of the normal go commands (build/install/test). The Go toolchain will resolve and fetch the featureguards-go module automatically.

Alternatively, you can also explicitly go get the package into a project:

go get -u github.com/featureguards/featureguards-go/v2

Documentation

For details on all the functionality in this library, see the Go documentation.

Below are a few simple examples:

IsOn

// Create the client once.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// The only require parameter is the API Key. Other options are available. See [goref].
ft := featureguards.New(ctx, featureguards.WithApiKey("API_KEY"), featureguards.WithDefaults(map[string]bool{"TEST": true}))

// Call IsOn multiple times.
on, err := ft.IsOn("TEST")

IsOn with attributes

// Create the client once.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// The only require parameter is the API Key. Other options are available. See [goref].
ft := featureguards.New(ctx, featureguards.WithApiKey("API_KEY"), featureguards.WithDefaults(map[string]bool{"TEST": true}))

// Call IsOn multiple times.
on, _ := ft.IsOn("FOO", featureguards.WithAttributes(
	featureguards.Attributes{}.Int64("user_id", 123).String("company_slug", "acme")))