Skip to main content

Flagsmith Go SDK

The SDK client for Go https://flagsmith.com/. Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and organisations.

The source code for the client is available on Github.

Getting Started

go get github.com/Flagsmith/flagsmith-go-client
import (
"github.com/Flagsmith/flagsmith-go-client"
)

Basic Usage

The SDK is initialised against a single environment within a project on https://flagsmith.com, for example the Development or Production environment. You can find your environment key in the Environment settings page.

API Key

Retrieving feature flags for your project

For full documentation visit https://docs.flagsmith.com

Sign Up and create account at https://flagsmith.com/

In your application initialise the Flagsmith client with your API key

fs := flagsmith.DefaultClient("<Your API Key>")

To check if a feature flag exists and is enabled:

fs := flagsmith.DefaultClient("<Your API Key>")
enabled, err := fs.FeatureEnabled("cart_abundant_notification_ab_test_enabled")
if err != nil {
log.Fatal(err)
} else {
if (enabled) {
fmt.Printf("Feature enabled")
}
}

To get the configuration value for feature flag value:

feature_value, err := fs.GetValue("cart_abundant_notification_ab_test")
if err != nil {
log.Fatal(err)
} else {
fmt.Printf(feature_value)
}

More examples can be found in the Tests

Override default configuration

By default, client is using default configuration. You can override configuration as follows:

fs := flagsmith.NewClient("<Your API Key>", flagsmith.Config{BaseURI: "<Your API URL>"})