SDK Reference
GoGreen provides production-ready SDKs in six languages: Go, TypeScript, Python, Java, Rust, and C# / .NET. All SDKs support local evaluation, real-time streaming, event tracking, multi-region failover, and offline mode. Choose your language below for install commands and full documentation.
All SDKs
| Language | Install | Documentation |
|---|---|---|
| Go | go get github.com/MarkDurbin104/GoGreen/sdk/go | Full reference below |
| TypeScript | npm install @gogreenflags/sdk | Full reference below |
| Python | pip install gogreen-sdk or pip install git+https://github.com/MarkDurbin104/GoGreen.git#subdirectory=sdk/python | Python SDK → |
| Java | Maven: com.gogreen:gogreen-sdk:1.0.0 / Gradle: implementation 'com.gogreen:gogreen-sdk:1.0.0' | Java SDK → |
| Rust | Add gogreen-sdk = "0.1" to Cargo.toml or use git dependency (see Rust SDK →) | Rust SDK → |
| C# / .NET | dotnet add package GoGreen.Sdk | C# SDK → |
Go SDK
Installation
go get github.com/MarkDurbin104/GoGreen/sdk/goInitialization
import (
gogreen "github.com/MarkDurbin104/GoGreen/sdk/go"
shared "github.com/MarkDurbin104/GoGreen/lib/shared-data"
)
client, err := gogreen.NewClient(gogreen.Config{
SDKKey: "YOUR_SDK_KEY",
EnvID: "YOUR_ENV_ID",
APIBaseURL: "https://app.gogreenflags.com",
StreamURL: "https://app.gogreenflags.com",
EventsURL: "https://app.gogreenflags.com",
EnableStreaming: true,
PollInterval: 30 * time.Second,
RequestTimeout: 5 * time.Second,
FlushInterval: 60 * time.Second,
})
if err != nil {
log.Fatal(err)
}
defer client.Close()Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
SDKKey | string | required | SDK key from Environment Settings |
EnvID | string | required | Environment ID |
APIBaseURL | string | localhost:8091 | Evaluation API base URL |
StreamURL | string | localhost:8094 | Streaming service URL |
EventsURL | string | localhost:8093 | Events ingestion URL |
EnableStreaming | bool | false | Enable real-time SSE updates |
PollInterval | Duration | 30s | Polling interval (when streaming is disabled) |
RequestTimeout | Duration | 5s | HTTP request timeout |
FlushInterval | Duration | 60s | Event flush interval |
Offline | bool | false | Offline mode (no network calls) |
BootstrapConfig | *EnvironmentConfig | nil | Pre-loaded config (skip initial fetch) |
AllAttributesPrivate | bool | false | Redact all user attributes in events |
PrivateAttributes | []string | nil | Specific attributes to redact |
APIBaseURLs | []string | nil | Multi-region failover URLs (overrides APIBaseURL) |
StreamURLs | []string | nil | Multi-region failover stream URLs |
Evaluating Flags
user := shared.EvaluationContext{
Key: "user-123",
Custom: map[string]interface{}{
"plan": "enterprise",
"country": "US",
},
}
// Simple evaluation
enabled := client.BoolVariation("feature-x", user, false)
theme := client.StringVariation("ui-theme", user, "light")
limit := client.NumberVariation("rate-limit", user, 100)
config := client.JSONVariation("feature-config", user, map[string]interface{}{})
// Detailed evaluation (includes reason, variation index, rule index)
val, detail := client.BoolVariationDetail("feature-x", user, false)
fmt.Printf("Value: %v, Reason: %s\n", val, detail.Reason)
// Reasons: FALLTHROUGH, RULE_MATCH, TARGET_MATCH, PREREQUISITE_FAILED, OFF, ERRORTracking Events
// Track custom events for experimentation
client.Track("purchase", user, map[string]any{
"revenue": 49.99,
"currency": "USD",
})Event Listeners
// Listen for flag changes
client.On("config_updated", func(data interface{}) {
fmt.Println("Flags updated!")
})
// Listen for diagnostic events
client.On("diagnostic", func(data interface{}) {
event := data.(gogreen.DiagnosticEvent)
fmt.Printf("Status: %s\n", event.ConnectionStatus)
})
// Listen for errors
client.On("error", func(data interface{}) {
fmt.Printf("Error: %v\n", data)
})Testing
// Create an offline test client with predetermined flag values
client, _ := gogreen.NewTestClient(map[string]interface{}{
"feature-x": true,
"ui-theme": "dark",
"rate-limit": 50,
})
// Use in tests — no network calls
enabled := client.BoolVariation("feature-x", user, false) // returns trueMulti-Region Failover
client, _ := gogreen.NewClient(gogreen.Config{
SDKKey: "YOUR_SDK_KEY",
EnvID: "YOUR_ENV_ID",
// Try URLs in order; fall back on connection failure
APIBaseURLs: []string{
"https://eval-us.gogreenflags.com",
"https://eval-eu.gogreenflags.com",
},
StreamURLs: []string{
"https://stream-us.gogreenflags.com",
"https://stream-eu.gogreenflags.com",
},
})TypeScript SDK
Installation
npm install @gogreenflags/sdkInitialization
The @gogreenflags/sdk package uses CommonJS. In TypeScript or CommonJS projects the standard import works directly. For ESM projects ("type": "module" in package.json), use createRequire:
// CommonJS / TypeScript (works out of the box)
const { GoGreenClient } = require('@gogreenflags/sdk');
// ESM projects
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const { GoGreenClient } = require('@gogreenflags/sdk');import { GoGreenClient } from '@gogreenflags/sdk'; // TypeScript with CommonJS moduleResolution
const client = new GoGreenClient({
sdkKey: 'YOUR_SDK_KEY',
environmentId: 'YOUR_ENV_ID',
apiBaseUrl: 'https://app.gogreenflags.com',
streamUrl: 'https://app.gogreenflags.com',
eventsUrl: 'https://app.gogreenflags.com',
enableStreaming: true,
defaultContext: {
key: 'user-123',
custom: { plan: 'enterprise' },
},
});Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
sdkKey | string | required | SDK key from Environment Settings |
environmentId | string | required | Environment ID |
defaultContext | EvaluationContext | required | Default user context |
apiBaseUrl | string | localhost:8091 | Evaluation API base URL |
streamUrl | string | optional | Streaming service URL |
eventsUrl | string | optional | Events ingestion URL |
enableStreaming | boolean | false | Enable real-time SSE updates |
requestTimeout | number | 5000 | HTTP request timeout (ms) |
flushInterval | number | 60000 | Event flush interval (ms) |
offline | boolean | false | Offline mode |
bootstrap | EvaluationResponse | undefined | Pre-loaded config (skip initial fetch) |
allAttributesPrivate | boolean | false | Redact all user attributes |
privateAttributes | string[] | [] | Specific attributes to redact |
piiKeyStrategy | 'hash' | 'mask' | 'drop' | 'hash' | PII redaction strategy for user key |
piiAttrStrategy | 'hash' | 'mask' | 'drop' | 'mask' | PII redaction strategy for attributes |
configRetryMaxAttempts | number | 5 | Max retry attempts for config fetch |
apiBaseUrls | string[] | undefined | Multi-region failover URLs |
streamUrls | string[] | undefined | Multi-region failover stream URLs |
Evaluating Flags
// Simple evaluation
const enabled = client.boolVariation('feature-x', false);
const theme = client.stringVariation('ui-theme', 'light');
const limit = client.numberVariation('rate-limit', 100);
const config = client.jsonVariation('feature-config', {});
// Detailed evaluation
const detail = client.boolVariationDetail('feature-x', false);
console.log(detail.value); // true
console.log(detail.reason); // "RULE_MATCH"
console.log(detail.variationIndex); // 0
console.log(detail.ruleIndex); // 1Tracking Events
// Track custom events for experimentation
client.track('purchase', { revenue: 49.99, currency: 'USD' });Event Listeners
// Listen for flag changes
client.on('configUpdated', () => {
console.log('Flags updated!');
});
// Listen for errors
client.on('error', (err) => {
console.error('SDK error:', err);
});Testing
import { testClient } from '@gogreenflags/sdk';
// Create an offline test client
const client = testClient({
'feature-x': true,
'ui-theme': 'dark',
'rate-limit': 50,
});
// Use in unit tests — no network calls
const enabled = client.boolVariation('feature-x', false); // returns trueBootstrap (SSR / Hydration)
// Server: embed config in HTML
const config = await fetchConfig();
res.send(`<script>window.__GOGREEN_BOOTSTRAP__ = ${JSON.stringify(config)}</script>`);
// Client: use bootstrap to avoid flash of default values
const client = new GoGreenClient({
sdkKey: 'YOUR_SDK_KEY',
environmentId: 'YOUR_ENV_ID',
defaultContext: { key: 'user-123' },
bootstrap: window.__GOGREEN_BOOTSTRAP__,
});