Skip to content

Go SDK

Terminal window
go get github.com/seal0-app/sdk-go

Standard library only, with no dependencies. Go 1.23 or later. Source and issues: github.com/seal0-app/sdk-go (Apache-2.0).

import seal0 "github.com/seal0-app/sdk-go"
client, err := seal0.New(os.Getenv("SEAL0_API_KEY")) // keep the key on the server

Options: seal0.WithBaseURL (default https://api.seal0.app), seal0.WithHTTPClient, seal0.WithMaxRetries (default 2).

ev, err := client.Evaluate(ctx, "cus_test_0001", "max_projects")
if err != nil {
return deny() // unknown Customer or feature, auth or network failure: fail closed
}
if n, unlimited, ok := ev.Entitlement.Value.Limit(); ok && (unlimited || projects < n) {
return allow()
}
  • Every feature at once: client.EvaluateAll(ctx, "cus_test_0001").
  • Reading values: Value.Bool(), Limit() (number and metered), Enum(), IsUnlimited(). Build values with seal0.BoolValue, NumberValue, UnlimitedValue and EnumValue.
  • Metered results carry Entitlement.Usage: used, limit, remaining, over limit and the period.
switch {
case errors.Is(err, seal0.ErrCustomerNotFound):
case errors.Is(err, seal0.ErrFeatureNotFound):
}
var apiErr *seal0.APIError
if errors.As(err, &apiErr) {
log.Printf("seal0: %s (request %s)", apiErr.Code, apiErr.RequestID)
}

*seal0.APIError carries Status, Code, Field and RequestID. See Errors and retries.

Every API operation has a method: CreateFeature, UpdateFeature, CreatePlan, PutDraft, PublishPlan, UpsertCustomer, AssignSubscription, UpdateSubscription, ChangePlanVersion, CreateOverride, RevokeOverride, RecordUsage, and the matching getters and lists.

  • PATCH fields: seal0.Set(v) changes a field, seal0.Null[T]() clears it, and leaving it unset keeps it.
  • Lists: for f, err := range client.Features(ctx) { … } pages through everything.
  • Idempotency: every mutation sends an Idempotency-Key, reused across retries. Choose your own with seal0.WithIdempotencyKey.

Automating setup has a full example.