Go
Idiomatic Go client with generics, automatic reconnection, and full
context.Context support. Requires Go 1.24+.
Install
go get github.com/shipsilently/shipsilently-goInitialize the client
Construct one client per process; it's safe for concurrent use.
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.
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, variantEvaluate all flags at once
Use EvaluateAll at request boundaries to fetch every flag for a
user in a single round trip.
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.
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:APIKeyrequired;APIURLandHTTPoptional.shipsilently.UserContext:map[string]anyof 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.