Go SDK

The DeployRamp Go SDK lets you evaluate feature flags, set user traits, and report errors for automatic rollback in any Go application.

Installation

go get github.com/deployramp/deployramp-go

Initialization

Import the package and call Init() with a Config struct. Optionally pass initial traits that will be sent with every flag evaluation. Init returns an error if the SDK cannot connect to the DeployRamp service.

import deployramp "github.com/deployramp/deployramp-go"

func main() {
    err := deployramp.Init(deployramp.Config{
        PublicToken: "pk_live_abc123",
        Traits: map[string]string{"plan": "pro"},
    })
    if err != nil {
        log.Fatal(err)
    }
    defer deployramp.Close()
}

Evaluating Flags

Use Flag() to check whether a feature is enabled. It returns false if the SDK has not been initialized. You can pass trait overrides to evaluate the flag for a different context without changing the global traits.

if deployramp.Flag("new-checkout") {
    renderNewCheckout()
} else {
    renderOldCheckout()
}

// With trait overrides
enabled := deployramp.Flag("beta-feature", map[string]string{"role": "admin"})

Setting Traits

Call SetTraits() to replace the current global traits. These traits are sent with every subsequent flag evaluation.

deployramp.SetTraits(map[string]string{"plan": "enterprise", "region": "eu-west"})

Error Reporting

Report errors to DeployRamp so it can correlate failures with flag states and trigger automatic rollbacks when error rates spike.

if err := processPayment(); err != nil {
    deployramp.Report(err, "new-checkout")
}

Shutdown

Call Close() before your process exits to flush pending evaluations and disconnect the WebSocket connection. Using defer after initialization is the idiomatic approach.

defer deployramp.Close()

API Reference

FunctionParametersReturnsDescription
Initconfig Config PublicToken string, optional BaseURL, Traits map[string]stringerrorInitializes the SDK with your project token and optional default traits.
Flagname string, traitOverrides ...map[string]stringboolEvaluates a feature flag. Returns false if the SDK is not initialized.
SetTraitstraits map[string]stringReplaces the current global traits.
Reporterr error, flagName string, traitOverrides ...map[string]stringReports an error for auto-rollback correlation.
CloseFlushes pending evaluations and disconnects the WebSocket.

We use cookies to analyze site usage and improve your experience.