Go SDK
The Unleash Go SDK lets you evaluate feature flags in your Go services and applications.
You can use this SDK with Unleash Enterprise or Unleash Open Source.
Requirements
- Go 1.21 or later (the SDK is tested against Go 1.21.x through 1.26.x)
Installation
Install the SDK module:
Configuration
Pass configuration options to unleash.Initialize(...) (global client) or unleash.NewClient(...) (instance client).
Base URL to your Unleash or Edge API, for example: https://<your-unleash-instance>/api/.
Name of your application. Included in registration, metrics, and request headers.
Additional headers for all API requests. Use this to add Authorization.
Environment value included in the static Unleash context.
Explicit instance ID for this SDK process. If omitted, the SDK generates one.
How often (in seconds) the SDK polls for updated flag configuration.
How often (in seconds) the SDK sends usage metrics to Unleash.
Disables client registration and metrics posting when set to true.
Restricts flag fetches to a single project. Prefer using a project scoped API token instead.
Directory used by storage implementations for persisted SDK state.
Custom storage implementation for local persistence and bootstrapping. See bootstrap flag data.
Registers custom activation strategies. See custom strategies.
Custom *http.Client for transport settings. Configure proxy, TLS, and timeouts using the Go standard libraryhttp.Client. This is also how you configure an outbound network proxy.
Listener implementation for SDK events (errors, ready/update, metrics, impression data).
Initialization
Initialize the SDK early in your application’s lifecycle.
Connection options
Backend SDKs communicate with Unleash or Unleash Edge through the Client API and require a backend token. They fetch flag configuration and evaluate flags locally in your application.
Set WithUrl to the base API endpoint of your Unleash or Unleash Edge instance, typically https://<your-unleash-instance>/api/. The URL pattern is the same in both cases. Use Unleash Edge when you need lower latency or higher availability.
Set WithCustomHeaders to include an Authorization header with a backend token. See API tokens for how to generate one.
Configure an HTTP proxy
The SDK uses Go’s standard HTTP proxy environment variables.
Set HTTPS_PROXY or HTTP_PROXY in the environment where your service runs:
Wait until the SDK is ready
Until the SDK loads flag data, boolean checks return false and variant checks return a disabled variant. See Check flags for details on evaluation methods and fallback behavior.
- Bootstrap data: if a bootstrap is provided the SDK loads data from it synchronously on creation, if the bootstrap fails to load it will fall back to cached data.
- Cached data: if no bootstrap is available, the SDK attempts to load data from persistent storage synchronously on creation.
- Network fetch: the SDK fetches flag configuration from Unleash asynchronously on startup. The ready event fires on the first successful response from Unleash.
If bootstrap or cached data is available, the SDK can evaluate flags immediately. There is no need to wait for the network fetch.
Use WaitForReady to block until the SDK has completed its first network fetch. This is useful when you need guaranteed fresh data, but it will block even if bootstrap or cached data is already loaded. If the API is unreachable, WaitForReady blocks indefinitely.
Check flags
Check if a flag is enabled
Use IsEnabled with FeatureOptions:
FeatureOptions controls how IsEnabled evaluates a flag:
Evaluation context for this call. See Unleash context for how to pass the same context to both IsEnabled and GetVariant.
Fallback value used when the flag cannot be resolved and FallbackFunc is not set.
Fallback callback used when the flag cannot be resolved. If set, this takes precedence over Fallback.
Override for resolving flags without repository lookup. This exists for backwards compatibility and is usually not needed in v6.
Fallback precedence when a flag is missing:
FallbackFuncFallbackfalse
Example with fallback:
Check a flag’s variant
Use GetVariant with VariantOptions:
VariantOptions controls how GetVariant evaluates variants:
Evaluation context for this call. See Unleash context for how to pass the same context to both IsEnabled and GetVariant.
Fallback variant used when no variant can be resolved and VariantFallbackFunc is not set.
Fallback callback used when no variant can be resolved. If set, this takes precedence over VariantFallback.
Override for resolving flags without repository lookup. This exists for backwards compatibility and is usually not needed in v6.
Fallback precedence when a variant cannot be resolved:
VariantFallbackFuncVariantFallback- SDK default disabled variant
Example with variant fallback:
The SDK can return two forms of the disabled variant:
- Feature disabled or not found:
{ name: "disabled", enabled: false, featureEnabled: false } - Feature enabled but no variant resolved (for example no variants configured):
{ name: "disabled", enabled: false, featureEnabled: true }
In both cases, name is disabled. The enabled: false field marks this as the SDK’s default fallback variant, which disambiguates it from a real variant that happens to be named "disabled".
Unleash context
Use Unleash context to drive strategy and constraint evaluation for both IsEnabled and GetVariant.
For stable gradual rollout and stickiness, include at least userId or sessionId.
Bootstrap flag data
Bootstrapping lets the SDK start from predefined flag configuration instead of waiting for the first network response.
BootstrapStorage falls back to the default on-disk cache if bootstrap parsing fails.
Custom bootstrap
If you need more control over the bootstrap source, you can implement your own Storage and pass it with WithStorage(...).
Your bootstrap payload must match the /client/features response format
Local caching and offline behavior
The default storage persists the latest feature payload to {backupPath}/unleash-repo-schema-v1-{appName}.json
By default, backupPath is os.TempDir(). On startup, the SDK loads cached state first, then fetches fresh data from Unleash.
If Unleash is temporarily unreachable:
- The SDK continues serving cached or bootstrapped values.
- Polling continues on
WithRefreshInterval. - Flag evaluations fall back to
false(or configured fallbacks) when no data exists.
Events
Implement listener interfaces and pass them with WithListener(...).
Use unleash.DebugListener{} during development for built-in logging of all event types.
Impact metrics
Impact metrics are lightweight, application-level time-series metrics stored and visualized directly inside Unleash. Use them to connect application data, such as request counts, error rates, or latency, to your feature flags and release plans.
The SDK automatically attaches appName, and environment labels to all impact metrics.
Initialize the SDK and publish impact metrics with package-level functions.
Metric types
Counter
Gauge
Histogram
Use counters for cumulative values that only increase, such as the total number of requests or errors.
Impact metrics are batched and sent on the same interval as standard SDK metrics (WithMetricsInterval).
Custom strategies
Register custom strategies with WithStrategies(...).
Then pass it:
Unit testing
For unit tests, use an in-memory bootstrap storage and disable metrics. This gives deterministic flag state without depending on a real Unleash instance.
The Go SDK does not have a direct disableRefresh option, so tests typically set a long WithRefreshInterval(...).
The SDK exposes the NewClient method so you can create scoped instances for testing purposes, rather than the singleton instance created with Initialize.
Troubleshooting
SDK does not become ready
If WaitForReady() blocks indefinitely:
- Verify
WithUrlpoints to your Unleash API base URL (for example,https://<your-instance>/api/). - Verify
WithCustomHeadersincludes a valid backend API token inAuthorization. - Confirm network connectivity from your service to the Unleash instance.
- Attach
unleash.DebugListener{}or your ownOnError/OnWarninghandlers to inspect failures.
All flags evaluate to false
If IsEnabled always returns false:
- Confirm the flag exists (check for typos).
- Confirm the flag is enabled in the target environment.
- Verify your Unleash context fields match your rollout strategy and constraints.
- Verify the SDK completed initial sync (
OnReadyfired, orWaitForReady()returned).