SDK

Go

Idiomatic Go client with generics, automatic reconnection, and full context.Context support. Requires Go 1.24+.

Install

terminal
go get github.com/shipsilently/shipsilently-go

Initialize the client

Construct one client per process; it's safe for concurrent use.

main.go
package main

import (
    "context"
    "log"
    "os"

    shipsilently "github.com/shipsilently/shipsilently-go"
)

func main() {
    client := shipsilently.New(shipsilently.Config{
        APIKey: os.Getenv("SHIPSILENTLY_KEY"),
    })

    ctx := context.Background()
    _ = client
    _ = ctx
    _ = log.Println
}

Evaluate a single flag

The package-level Evaluate[T] generic returns the flag value typed as T, or the default on any error.

checkout.go
userCtx := shipsilently.UserContext{
    "userId":  user.ID,
    "plan":    user.Plan,
    "country": user.Country,
}

enabled, err := shipsilently.Evaluate[bool](
    ctx, client, "new-checkout-v2", userCtx, false,
)
if err != nil {
    log.Printf("flag eval error: %v", err)
}

variant, _ := shipsilently.Evaluate[string](
    ctx, client, "hero-variant", userCtx, "control",
)
_, _ = enabled, variant

Evaluate all flags at once

Use EvaluateAll at request boundaries to fetch every flag for a user in a single round trip.

handler.go
flags, err := client.EvaluateAll(ctx, userCtx)
if err != nil {
    log.Printf("batch eval error: %v", err)
}

for key, result := range flags {
    log.Printf("%s = %v (%s)", key, result.Value, result.Reason)
}

Stream flag updates

Stream opens a Server-Sent Events connection and invokes your callback whenever a flag changes. It auto-reconnects on transient errors and cancels cleanly when ctx is done.

worker.go
cancel, err := client.Stream(ctx, userCtx, func(flags map[string]any) {
    log.Printf("flags updated: %v", flags)
})
if err != nil {
    log.Fatalf("stream error: %v", err)
}
defer cancel()

Types

  • shipsilently.Config: APIKey required; APIURL and HTTP optional.
  • shipsilently.UserContext: map[string]any of attributes used for targeting.
  • shipsilently.EvaluationResult: flag key, value, reason, and rule id.

Error handling

Every evaluation function returns the default value on error so your callers keep working through outages. Inspect err for logging or metrics, but don't gate user-visible behavior on it.