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
| Option | Description |
|---|---|
WithAuth(token string) | Set Bearer authentication token |
WithHTTPClient(client *http.Client) | Use custom HTTP client |
WithHeaders(headers map[string]string) | Add default headers to all requests |
Type System
Type Mapping Reference
| Contract Type | Go Type |
|---|---|
string | string |
bool | bool |
int, int32 | int32 |
int64 | int64 |
int8, int16 | int8, int16 |
uint, uint32 | uint32 |
uint64 | uint64 |
float32 | float32 |
float64 | float64 |
time.Time | time.Time |
json.RawMessage | json.RawMessage |
any | any |
[]T | []T |
map[string]T | map[string]T |
Struct Types
Contract struct types generate Go structs with JSON tags:Optional and Nullable Fields
Optional and nullable fields become pointers withomitempty:
| Contract Definition | Go Type | JSON Tag |
|---|---|---|
| Required field | T | json:"name" |
optional: true | *T | json:"name,omitempty" |
nullable: true | *T | json:"name" |
| Both optional and nullable | *T | json:"name,omitempty" |
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:Resources and Methods
Resource Pattern
Each contract resource becomes a struct attached to the client:Method Signatures
Generated method signatures follow these patterns:| Contract Method | Generated Signature |
|---|---|
| No input, no output | Method(ctx) error |
| No input, with output | Method(ctx) (*Output, error) |
| With input, no output | Method(ctx, *Input) error |
| With input, with output | Method(ctx, *Input) (*Output, error) |
context.Context as the first parameter for cancellation and timeout support.
Streaming (SSE)
For methods with streaming support, the generator creates anEventStream[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 anError 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
- Overview - Introduction to SDK generation
- Python - Generate Python clients
- TypeScript - Generate TypeScript clients
- Types - Contract type system
- REST Transport - Serve your API over REST