Go SDK
The Go client is shipped as a Go module. Requires Go 1.22+. The client always points at the production API at https://api.redpennon.dev (see DefaultAPIBaseURL in the client package); pass only the environment API key to NewClient.
Add the module
go get github.com/redpennon/sdks/go
Configure
package main
import (
"os"
redpennon "github.com/redpennon/sdks/go"
)
func main() {
c := redpennon.NewClient(os.Getenv("RP_API_KEY"))
_ = c
}
Evaluate a variable
VariableValue — value or default
value, _ := c.VariableValue(ctx, "show-banner", false, &redpennon.UserContext{
ID: "user-123",
})
enabled := value.(bool)
Returns the served value or defaultValue when the variable is unknown, not served, or a transport / non-2xx / governance error occurs. The returned error is always nil, matching the fail-open semantics of the Node and Python SDKs — call Variable directly if you need to observe the underlying error.
Variable — full result
result, err := c.Variable(ctx, "checkout-flow", &redpennon.UserContext{ID: "user-123"})
if err != nil {
// *redpennon.APIError on governance/auth errors
}
// result.Value, *result.Variation, result.Reason, *result.Feature,
// result.EvaluationTrace (string — empty when not present)
//
// Variation and Feature are *string and are nil when the platform
// served no value (unknown key, targeting disabled, feature deleted
// or archived).
Returns *VariableResult with all response fields. Use when you need Variation, Reason, or EvaluationTrace.
Variables — batch
results, err := c.Variables(ctx, []string{"show-banner", "discount-pct"}, user)
banner := results["show-banner"].Value
discount := results["discount-pct"].Value
Resolves multiple variables in one round-trip. Returns map[string]VariableResult.
VariableResult type
type VariableResult struct {
Key string `json:"key"`
Value any `json:"value"` // nil when not served
Variation *string `json:"variation"` // nil when not served
Reason string `json:"reason"`
Feature *string `json:"feature"` // nil when not served
EvaluationTrace string `json:"evaluation_trace,omitempty"` // opaque signed token
}
Track events
result, _ := c.Variable(ctx, "checkout-flow", &redpennon.UserContext{ID: "user-123"})
val := 49.99
_, err := c.TrackEvents(ctx, []redpennon.EventPayload{
{
Event: "purchase",
Variable: "checkout-flow",
Variation: result.Variation,
User: &redpennon.UserContext{ID: "user-123"},
Value: &val,
EvaluationTrace: result.EvaluationTrace,
},
})
TrackEvents POSTs to POST /v1/events and returns (*TrackEventsResult, error). Returns *APIError on non-202.
EventPayload type
type EventPayload struct {
Event string `json:"event"` // required
Variable string `json:"variable"` // required
Variation string `json:"variation"` // required
User *UserContext `json:"user,omitempty"`
Value *float64 `json:"value,omitempty"`
OccurredAt string `json:"occurred_at,omitempty"` // ISO-8601
EvaluationTrace string `json:"evaluation_trace,omitempty"`
}
See Ingest events for full field semantics and error codes.
Errors
HTTP error responses return *redpennon.APIError with StatusCode and Message. See API errors.