Configuration
The Go SDK is configured via toggly.Config.
User context belongs to each request
Boolean evaluation and catalog-local variant assignment both use definitions
fetched once. Prefer ambient request context (togglyhttp /
WithEvalContext) or a worker default (Config.Identity / SetIdentity).
Do not rebuild {Identity: …} on every call, and do not swap a shared client's
identity per concurrent HTTP user.
Identity precedence (first non-empty wins): per-call override → ambient
HTTP/session → Config.Identity / SetIdentity → empty. Groups come only from
ambient or per-call Context.
Required
- AppKey: your application key from Toggly
- Environment: environment name (e.g.
Production,Staging)
client, err := toggly.NewClient(toggly.Config{
AppKey: os.Getenv("TOGGLY_APP_KEY"),
Environment: os.Getenv("TOGGLY_ENV"),
})
Feature variants (catalog-local)
Variants assign locally from definitions (variants + allocation). There
is no EnableVariants toggle and no evaluated-variants-signed rail.
Requires Go SDK 0.10+ for Config.Identity / SetIdentity.
HTTP / middleware (preferred)
After togglyhttp (or any middleware that stores eval context on
r.Context()), pass an empty per-call Context:
v, err := client.GetVariant(r.Context(), "checkout-flow", toggly.Context{})
if err != nil {
return err
}
if v != nil {
_ = v.Name
_ = v.ConfigurationValue
}
CLI / worker
Set identity once at startup (or when the session begins):
client, err := toggly.NewClient(toggly.Config{
AppKey: "YOUR_APP_KEY",
Environment: "Production",
Identity: "user-123", // optional default
})
if err != nil {
return err
}
defer client.Close()
client.SetIdentity("user-123")
v, err := client.GetVariant(ctx, "checkout-flow", toggly.Context{})
GetVariant returns (nil, nil) when the feature is unknown, has no catalog
variants, or no allocation match. Pass a non-empty per-call Context only to
override ambient or client identity (for example impersonation).
Initialization is asynchronous; results become available after the first
successful definitions refresh.