Skip to content

Go SDK

Gov1.6.3
Terminal window
go get github.com/flags-gg/go-flags
package main
import (
"fmt"
flags "github.com/flags-gg/go-flags"
)
func main() {
client := flags.NewClient(
flags.WithAuth(flags.Auth{
ProjectID: "your-project-id",
AgentID: "your-agent-id",
EnvironmentID: "your-environment-id",
}),
)
if client.Is("new-feature").Enabled() {
fmt.Println("Feature is enabled!")
}
}
allFlags, err := client.List()
if err != nil {
log.Fatal(err)
}
for _, flag := range allFlags {
fmt.Printf("%s: %v\n", flag.Details.Name, flag.Enabled)
}

Check several flags in a single call:

// Returns map[string]bool of flag name to enabled status
results := client.GetMultiple("feature-1", "feature-2", "feature-3")
// Returns true only if every named flag is enabled
if client.AllEnabled("feature-1", "feature-2") {
fmt.Println("All features enabled")
}
// Returns true if any named flag is enabled
if client.AnyEnabled("premium", "beta") {
fmt.Println("At least one feature enabled")
}

Opt in to background refresh so flag lookups never block on the network. Always call Close() to stop the goroutine when the client is no longer needed:

client := flags.NewClient(
flags.WithAuth(auth),
flags.WithBackgroundRefresh(),
)
defer client.Close()