> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useshipd.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go

> Evaluate shipd flags locally in a Go service with one concurrent client and context per request.

## Overview

Add shipd to a Go 1.23+ service with one client per environment. Flag checks run in memory against a snapshot and make no network calls per request. This SDK uses polling for updates.

Define flags in [TypeScript or Go](/config-as-code/define-flags) and sync them with the CLI. Use a [server SDK key](/concepts/keys) for the environment.

## Install

```bash theme={null}
go get github.com/alasti-company/useshipd.com/sdks/go
```

## Create the client

```go main.go theme={null}
package main

import (
	"context"
	"log"
	"os"
	"time"

	shipd "github.com/alasti-company/useshipd.com/sdks/go"
)

func main() {
	client, err := shipd.New(shipd.Options{
		SDKKey: os.Getenv("SHIPD_SDK_KEY"),
		Defaults: map[string]any{
			"new-checkout":   false,
			"search-variant": "control",
			"max-retries":    3,
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
		defer cancel()
		// Shutdown delivers pending events, then closes the client.
		if err := client.Shutdown(ctx); err != nil {
			log.Printf("shipd events: %v", err)
		}
	}()

	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	if err := client.Ready(ctx); err != nil {
		log.Printf("shipd startup: %v; continuing with defaults", err)
	}
	cancel()

	user := shipd.EvaluationContext{
		UserID:     "usr_8f2k19",
		Attributes: map[string]any{"plan": "pro"},
	}
	log.Printf("new checkout: %v", client.IsEnabled("new-checkout", user))
	log.Printf("search: %s", client.GetVariant("search-variant", user))
	log.Printf("retries: %v", client.GetNumber("max-retries", user))
}
```

The client is safe to share across goroutines. Pass an evaluation context per request. Supply `country` or other location traits yourself when needed. `Identify` sends traits to shipd for audience insights and does not set a process-wide identity.

## Updates and failure handling

The client fetches a snapshot at startup and polls every 30 seconds using ETags. Network failures, malformed snapshots, and unsupported schema versions keep the last valid snapshot. Before any snapshot loads, configured defaults apply.

Use a bounded context with `Ready`, `Refresh`, and `Shutdown`. `LastError` exposes request failures. To stop, stop accepting new requests and drain in-flight handlers within a deadline before calling `Shutdown(ctx)`. Shutdown attempts to flush pending events, then closes the client even if delivery fails. `Close` stops immediately without delivering them.

This release has no WebSocket stream, disk cache, or remote identity overlay lookup. Pass traits on each evaluation context.

## Next

* [Go SDK reference](/reference/go-sdk)
* [Target users](/flags/targeting)
* [Roll out a flag to a percentage of users](/flags/percentage-rollouts)

## Definitions and generated accessors

Author definitions with `config.ShipdConfig` from `github.com/alasti-company/useshipd.com/sdks/go/config` in `shipd.config.go`. The shared CLI reads this Go source directly and generates Go accessors by default after push and pull, unless `typesLanguage` overrides it. Run `shipd types gen` to regenerate locally.

See [Define flags in code](/config-as-code/define-flags#go-definitions) and [Generate Go accessors](/config-as-code/types#go-output).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.