Go SDK
Use Toggly’s Go SDK for server-side, local evaluation of feature flags.
Grab the printable Go cheat sheet (download PDF) — net/http middleware, signed defs, snapshots, gRPC metrics.
- Module:
github.com/ops-ai/Toggly.FeatureManagement/toggly-go - Package:
github.com/ops-ai/Toggly.FeatureManagement/toggly-go/toggly - Go version: 1.24+
Installation
go get github.com/ops-ai/Toggly.FeatureManagement/toggly-go@latest
Quick start
package main
import (
"context"
"log"
"os"
"time"
"github.com/ops-ai/Toggly.FeatureManagement/toggly-go/toggly"
"github.com/ops-ai/Toggly.FeatureManagement/toggly-go/toggly/session"
)
func main() {
client, err := toggly.NewClient(toggly.Config{
AppKey: os.Getenv("TOGGLY_APP_KEY"),
Environment: "Production",
BaseURL: "https://app.toggly.io/",
// Optional cache for stable decisions from non-deterministic filters.
SessionStore: session.NewMemoryStore(),
SessionTTL: 30 * time.Minute,
// Optional features
EnableLiveUpdates: true,
})
if err != nil {
log.Fatal(err)
}
defer func() { _ = client.Close() }()
// Known user context is supplied before the first local evaluation.
// In an HTTP app, derive these values from the authenticated request.
evalCtx := toggly.Context{
Identity: "user-123",
Groups: []string{"beta"},
Traits: map[string]any{"country": "US"},
}
enabled, err := client.IsEnabled(context.Background(), "new-dashboard", evalCtx)
if err != nil {
log.Fatal(err)
}
_ = enabled
}
NewClient validates configuration and starts background loading; it does not wait for definitions to arrive. An early or unknown flag returns false by default. Keep a normal fallback experience available while the SDK loads, and handle evaluation errors before using the result. An empty app key returns an error: validate configuration or show setup instructions before constructing a client.
Try your first flag
- Create an app in Toggly and set
TOGGLY_APP_KEYlocally. Createnew-dashboardin itsProductionenvironment, initially off. - Start the application with an existing page or handler as the off-state fallback.
- Enable the flag with an Always On rule. After the SDK receives the update, the next evaluation changes without an application deployment.
- Add user targeting and evaluate two different authenticated request contexts. Normal Boolean evaluation downloads shared definitions and evaluates users locally; changing the context does not cause a second API call.
Remote variants use a separate fixed-context client mode. Supply its known identity, groups, and claims at construction rather than setting identity after initialization. Never mutate a shared variants client for individual HTTP requests.
Next steps
- Configuration
- Evaluation context & built-in filters
- Signed definitions (JWKS + ES256 verification)
- Snapshots (disk / in-memory)
- Live updates (WebSockets)
- Usage statistics & metrics (gRPC)
- Secure features & authorization hook
- Custom filters
- Integrations (HTTP, templates, context)
Sample catalog
Explore Toggly.Samples for runnable feature-flag workshops and their setup recipes. Use each sample's README for the exact packages, supported SDK surfaces, and manual walkthrough.