Go SDK
The RocketFlag Go SDK is a high-performance client for interacting with the RocketFlag API in your backend services.
Installation
Section titled “Installation”go get github.com/rocketflag/go-sdkBasic Usage
Section titled “Basic Usage”package main
import ( "fmt" "log" rocketflag "github.com/rocketflag/go-sdk")
func main() { // Initialize the client rf := rocketflag.NewClient()
// Fetch a flag flagKey := "your-flag-id" flag, err := rf.GetFlag(flagKey, rocketflag.UserContext{}) if err != nil { log.Fatalf("Error fetching flag: %v", err) }
if flag.Enabled { fmt.Printf("Feature '%s' is enabled!\n", flag.Name) }}Advanced Usage
Section titled “Advanced Usage”Working with Cohorts
Section titled “Working with Cohorts”Pass a UserContext with a “cohort” key:
userContext := rocketflag.UserContext{"cohort": "user@example.com"}flag, err := rf.GetFlag(flagKey, userContext)Working with Group Flags (Environments)
Section titled “Working with Group Flags (Environments)”Specify the environment in the UserContext:
userContext := rocketflag.UserContext{"env": "production"}flag, err := rf.GetFlag(flagKey, userContext)Protected Keys
Section titled “Protected Keys”Add the “key” to your UserContext:
userContext := rocketflag.UserContext{"key": "YOUR_PROTECTED_KEY"}flag, err := rf.GetFlag(flagKey, userContext)Custom Configuration
Section titled “Custom Configuration”Customize the client by passing functional options to NewClient:
rf := rocketflag.NewClient( rocketflag.WithAPIURL("https://api.custom.com"), rocketflag.WithVersion("v2"), rocketflag.WithHTTPClient(customHTTPClient),)