Skip to Content
SdksOverview

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

LanguageInstallDocumentation
Gogo get github.com/MarkDurbin104/GoGreen/sdk/goFull reference below
TypeScript / JavaScriptnpm install @gogreenflags/sdkTypeScript / JavaScript SDK →
Pythonpip install gogreen-sdk or pip install git+https://github.com/MarkDurbin104/GoGreen.git#subdirectory=sdk/pythonPython SDK →
JavaMaven: com.gogreen:gogreen-sdk:1.0.0 / Gradle: implementation 'com.gogreen:gogreen-sdk:1.0.0'Java SDK →
RustAdd gogreen-sdk = "0.1" to Cargo.toml or use git dependency (see Rust SDK →)Rust SDK →
C# / .NETdotnet add package GoGreen.SdkC# SDK →

Go SDK

Installation

go get github.com/MarkDurbin104/GoGreen/sdk/go

Initialization

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

OptionTypeDefaultDescription
SDKKeystringrequiredSDK key from Environment Settings
EnvIDstringrequiredEnvironment ID
APIBaseURLstringlocalhost:8091Evaluation API base URL
StreamURLstringlocalhost:8094Streaming service URL
EventsURLstringlocalhost:8093Events ingestion URL
EnableStreamingboolfalseEnable real-time SSE updates
PollIntervalDuration30sPolling interval (when streaming is disabled)
RequestTimeoutDuration5sHTTP request timeout
FlushIntervalDuration60sEvent flush interval
OfflineboolfalseOffline mode (no network calls)
BootstrapConfig*EnvironmentConfignilPre-loaded config (skip initial fetch)
AllAttributesPrivateboolfalseRedact all user attributes in events
PrivateAttributes[]stringnilSpecific attributes to redact
APIBaseURLs[]stringnilMulti-region failover URLs (overrides APIBaseURL)
StreamURLs[]stringnilMulti-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, ERROR

Tracking 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 true

Multi-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 & JavaScript SDK

Full reference: TypeScript / JavaScript → (install, GoGreenClient, streaming, events, SSR bootstrap).

npm install @gogreenflags/sdk