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-goInitialization
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
| Function | Parameters | Returns | Description |
|---|---|---|---|
Init | config Config — PublicToken string, optional BaseURL, Traits map[string]string | error | Initializes the SDK with your project token and optional default traits. |
Flag | name string, traitOverrides ...map[string]string | bool | Evaluates a feature flag. Returns false if the SDK is not initialized. |
SetTraits | traits map[string]string | — | Replaces the current global traits. |
Report | err error, flagName string, traitOverrides ...map[string]string | — | Reports an error for auto-rollback correlation. |
Close | — | — | Flushes pending evaluations and disconnects the WebSocket. |