Go SDK
Flipswitch SDK for Go with real-time SSE support
The Flipswitch Go SDK provides an OpenFeature-compatible provider with automatic cache invalidation via Server-Sent Events (SSE).
Requirements
- Go 1.21+
- OpenFeature SDK
Installation
Quick Start
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | Environment API key from dashboard |
WithBaseURL | string | https://api.flipswitch.dev | Your Flipswitch server URL |
WithRealtime | bool | true | Enable SSE for real-time flag updates |
WithHTTPClient | *http.Client | default | Custom HTTP client |
Evaluation Context
Pass user attributes for targeting:
Real-Time Updates
When WithRealtime(true) is set (default), the SDK maintains an SSE connection to receive instant flag changes:
- The SSE client receives a
flag-changeevent - The local cache is immediately invalidated
- Next flag evaluation fetches the fresh value
Event Listeners
Connection Status
Detailed Evaluation
Get full evaluation details including variant and reason:
Bulk Flag Evaluation
Evaluate all flags at once:
HTTP Server Integration
Gin Integration
Reconnection Strategy
The SSE client automatically reconnects with exponential backoff:
- Initial delay: 1 second
- Maximum delay: 30 seconds
- Backoff multiplier: 2x
When reconnected, the provider continues to work seamlessly.
Shutdown
Always shutdown the provider when done:
Use defer provider.Shutdown() right after creating the provider to ensure proper cleanup when your application exits.
Troubleshooting
SSE connection keeps disconnecting
Check if your proxy or load balancer supports long-lived connections. Configure timeout settings accordingly.
Flags not updating in real-time
Verify that WithRealtime(true) is set and check the SSE status:
Context cancellation
Make sure your context isn't being cancelled prematurely. Use context.Background() for long-running operations.