> ## 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 app

> A complete Go app with Go-authored definitions, generated accessors, and local flag evaluation.

## Overview

This tutorial defines four flags in Go, loads those definitions directly with the CLI, generates typed accessors, and evaluates flags for one user. You need Go 1.23+, Node.js 22.12+ for the CLI, and a shipd account.

For a step-by-step first flag, use the [quickstart](/quickstart). For the equivalent TypeScript application, see the [Node tutorial](/examples/node).

## Create the project

```bash theme={null}
mkdir shipd-go-example && cd shipd-go-example
go mod init example.com/shipd-quickstart
go get github.com/alasti-company/useshipd.com/sdks/go
npm install -g @shipdit/cli

```

## Define flags

Create `shipd.config.go`:

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

import "github.com/alasti-company/useshipd.com/sdks/go/config"

var Config = config.ShipdConfig{
	"new-checkout":     {Type: "boolean", Default: false, Description: "Redesigned checkout flow", Tags: []string{"checkout"}},
	"search-variant":   {Type: "variant", Default: "control", Variants: []string{"control", "semantic", "hybrid"}},
	"max-retries":      {Type: "number", Default: 3},
	"checkout-payload": {Type: "json", Default: map[string]any{"mode": "strict", "showPromo": true}},
}
```

The CLI discovers `shipd.config.go` and selects Go output automatically.

## Push and generate accessors

```bash theme={null}
shipd login
shipd push
shipd types gen
```

The CLI creates the flags in the selected project and environment, then writes `internal/flags/flags_gen.go`. Commit that file with `shipd.config.go`. The generator creates `Defaults()`, `NewCheckout`, `SearchVariant`, `MaxRetries`, and `CheckoutPayload`.

## Read flags

Create `main.go`. One client fetches a snapshot, then evaluates every check locally:

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

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

	"example.com/shipd-quickstart/internal/flags"
	shipd "github.com/alasti-company/useshipd.com/sdks/go"
)

func main() {
	client, err := shipd.New(shipd.Options{
		SDKKey:   os.Getenv("SHIPD_SDK_KEY"),
		Defaults: flags.Defaults(),
	})
	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("checkout=%v search=%s retries=%v", flags.NewCheckout(client, user), flags.SearchVariant(client, user), flags.MaxRetries(client, user))
}
```

## Run

Create a **server** SDK key for the same environment in the dashboard, then run:

```bash theme={null}
export SHIPD_SDK_KEY=shipd_sdk_server_…
go run .
```

The program logs the checkout, search variant, and retry count, then flushes diagnostic events before closing. If the first snapshot cannot load within five seconds, it logs the error and uses the generated defaults.

For a long-running service, reuse the client and pass an `EvaluationContext` on each request. Polling refreshes the snapshot every 30 seconds by default. `Identify` queues telemetry; it does not set a global evaluation identity.

## Next

* [Go SDK setup](/sdks/go) and [Go reference](/reference/go-sdk)
* [Target users](/flags/targeting)
* [Sync flags in CI](/config-as-code/ci)


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