Skip to content

Go Configuration

The Go SDK uses functional options for configuration:

client := flags.NewClient(
flags.WithAuth(flags.Auth{
ProjectID: "your-project-id",
AgentID: "your-agent-id",
EnvironmentID: "your-environment-id",
}),
flags.WithBaseURL("https://custom-api.flags.gg"),
flags.WithMaxRetries(5),
flags.WithMemory(),
)
OptionDefaultDescription
WithAuth(Auth)Required. Set project, agent, and environment IDs
WithBaseURL(string)https://api.flags.ggCustom API endpoint
WithMaxRetries(int)3Max retry attempts on failure
WithMemory()SQLiteUse in-memory cache instead of SQLite
SetFileName(*string)/tmp/flags.dbCustom SQLite database path
WithBackgroundRefresh()offRefresh flags asynchronously in a goroutine instead of inline on each lookup
WithErrorHandler(func(error))Callback invoked whenever a refresh or fetch error occurs
MethodDescription
Is(name string) *FlagGet a flag wrapper, then call .Enabled()
List() ([]FeatureFlag, error)Return all cached flags
GetMultiple(names ...string) map[string]boolLook up several flags in one call
AllEnabled(names ...string) boolTrue if every named flag is enabled
AnyEnabled(names ...string) boolTrue if any named flag is enabled
Close()Stop the background refresh goroutine and wait for it to exit

The client is safe for concurrent use. All operations use sync.RWMutex internally.

The client handles errors gracefully:

  • API failures fall back to cached values
  • Unknown flags return false (disabled)
  • The circuit breaker prevents cascading failures after 3 consecutive errors
  • Errors during background refresh are reported via WithErrorHandler if configured