Go Configuration
Client Options
Section titled “Client Options”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(),)Options Reference
Section titled “Options Reference”| Option | Default | Description |
|---|---|---|
WithAuth(Auth) | — | Required. Set project, agent, and environment IDs |
WithBaseURL(string) | https://api.flags.gg | Custom API endpoint |
WithMaxRetries(int) | 3 | Max retry attempts on failure |
WithMemory() | SQLite | Use in-memory cache instead of SQLite |
SetFileName(*string) | /tmp/flags.db | Custom SQLite database path |
WithBackgroundRefresh() | off | Refresh flags asynchronously in a goroutine instead of inline on each lookup |
WithErrorHandler(func(error)) | — | Callback invoked whenever a refresh or fetch error occurs |
Client Methods
Section titled “Client Methods”| Method | Description |
|---|---|
Is(name string) *Flag | Get a flag wrapper, then call .Enabled() |
List() ([]FeatureFlag, error) | Return all cached flags |
GetMultiple(names ...string) map[string]bool | Look up several flags in one call |
AllEnabled(names ...string) bool | True if every named flag is enabled |
AnyEnabled(names ...string) bool | True if any named flag is enabled |
Close() | Stop the background refresh goroutine and wait for it to exit |
Thread Safety
Section titled “Thread Safety”The client is safe for concurrent use. All operations use sync.RWMutex internally.
Error Handling
Section titled “Error Handling”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
WithErrorHandlerif configured