Overview
Importgithub.com/alasti-company/useshipd.com/sdks/go as shipd. All evaluation methods are safe to call concurrently and run locally. See Go for installation and a complete example.
New
string
required
The environment’s server SDK key.
Zero durations select defaults. Negative
RefreshInterval and FetchTimeout values are rejected; negative flush options behave as shown above. Custom HTTP clients must honor request contexts and control their own redirect behavior.
Returns a client that immediately starts fetching a snapshot.
Errors. Invalid configuration returns an error. Background fetch failures are exposed through LastError.
Evaluation methods
string
required
The flag key, such as
new-checkout.EvaluationContext
required
Request-scoped
UserID, scalar Attributes, and optional SegmentIDs. Use shipd.EvaluationContext{} for anonymous evaluation. Set UserIDPresent: true to compare an explicitly empty UserID; empty IDs do not satisfy exists or provide a rollout bucket.Evaluate also returns Reason, RuleID, and a nullable SnapshotVersion. JSON values are copied, and JSON numbers decode as float64.
Fallback. Before a snapshot loads or for an unknown key, configured defaults apply. Built-in typed defaults are false, "control", 0, and an empty JSON object. Disabled flags use the snapshot default. Boolean, variant, and number getters use a correctly typed configured default, or their built-in default, when the resulting value has the wrong type. Evaluate uses nil for an unknown key without a configured default.
Errors. Evaluation methods return values without errors. Failed refreshes keep the last valid snapshot. Evaluation continues after Close with the last snapshot or defaults. Evaluation values that exceed the event payload limit are omitted from telemetry.
Ready
nil once a snapshot loads, or immediately when Bootstrap is set.
Errors. Returns the initial fetch error as soon as that attempt fails. The client then serves defaults, and polling (unless disabled) keeps trying. Returns the context error on timeout or cancellation while the first fetch is still in flight, or ErrClosed after close, even if a snapshot previously loaded.
Refresh
nil for a successful fetch or 304 response with an existing snapshot.
Errors. Request, response, and parsing errors are returned and stored in LastError. Returns ErrClosed after close.
Identify
string
required
A nonempty user ID of at most 256 UTF-16 code units.
Name is optional and limited to 256 UTF-16 code units. Traits supports at most 100 entries: nonempty keys up to 128 UTF-16 code units, with scalar JSON values or nil. Strings are limited to 1024 UTF-16 code units.
Returns nil after queueing, including when events are disabled.
Errors. Invalid identity data or identify events that exceed the payload limit return a validation error. Returns ErrClosed after close.
Flush
FlushInterval and as soon as FlushAt events are buffered. The buffer retains at most 200 events; failed batches are requeued, with oldest entries dropped on overflow (see DroppedEvents). After a failed delivery, automatic retries wait for the next interval. Evaluation events include values and user IDs; evaluation attributes stay local. Flush splits batches to respect the edge limit of 100 events and 256 KiB per request.
Returns nil after success, with an empty buffer, or when events are disabled.
Errors. Delivery errors are returned and stored in LastError. Returns ErrClosed after close, including when events are disabled. Use a bounded context for shutdown flushing.
LastError
nil. A successful refresh or flush, including an empty flush, clears it.
SnapshotVersion
ok is false until the first valid snapshot arrives. Unlike Evaluate, it records no event, so it suits health checks.
DroppedEvents
Shutdown
ctx (including events from a background flush that is still in progress), then closes the client even if delivery fails. Events already discarded on buffer overflow cannot be delivered; check DroppedEvents. Events recorded after Shutdown starts are not delivered. Use it for graceful shutdown with a bounded context. Repeated calls are safe.
Returns nil after events are delivered, or when events are disabled.
Errors. Returns the flush error if delivery fails or ctx expires. The client is closed either way.
Close
Shutdown to deliver them first. Close implements io.Closer. Repeated calls are safe.
Returns nil.
Errors
Match them with
errors.Is, because returned errors may wrap them:
Flag definitions
Go flag definitions live in thegithub.com/alasti-company/useshipd.com/sdks/go/config subpackage of the same module. Declare config.ShipdConfig directly; the runtime SDK only evaluates flags. See Go config reference for its types, validation, export, and defaults methods.