Skip to main content
The Go SDK generator creates native Go client libraries from your contract definitions. The generated code uses only the standard library, requires no external dependencies, and provides a resource-based API with full type safety.

Key Features

  • Zero Dependencies: Only uses Go’s standard library (net/http, encoding/json)
  • Single File Output: One self-contained Go file
  • Resource-Based API: Intuitive access (client.Todos.Create())
  • Full Type Safety: Complete Go types with proper JSON tags
  • SSE Streaming: Built-in EventStream[T] for server-sent events
  • Union Types: Proper marshal/unmarshal for discriminated unions

Quick Start

Step 1: Define Your Contract

Step 2: Generate the SDK

Step 3: Use the Generated Client

Generated Code Structure

The generated file contains everything in a single package:

Client Configuration

Creating a Client

Available Options

Type System

Type Mapping Reference

Struct Types

Contract struct types generate Go structs with JSON tags:

Optional and Nullable Fields

Optional and nullable fields become pointers with omitempty: Example:

Enum Fields

Enum fields generate as the base type with a comment:

Slice and Map Types

Union Types (Discriminated)

Union types generate a struct with pointer fields for each variant, plus marshal/unmarshal methods:
Usage:

Resources and Methods

Resource Pattern

Each contract resource becomes a struct attached to the client:
Access resources through the client:

Method Signatures

Generated method signatures follow these patterns: All methods take context.Context as the first parameter for cancellation and timeout support.

Streaming (SSE)

For methods with streaming support, the generator creates an EventStream[T] type:

Stream Method Signature

EventStream API

Streaming Usage

Cancellation

Use context cancellation to stop a stream early:

Error Handling

Error Type

Generated code includes an Error type for API errors:

Checking Errors

Advanced Usage

Custom HTTP Client

Context Usage

Always pass context for proper cancellation and timeout:

Concurrent Requests

Complete Example

Server

Client Usage

See Also