Test mode: plans are proposed and nobody is charged yet.

← Docs

Camshaft client for Go

A Go client for Camshaft's HTTP API (docs/openapi.json): flows, runs, events, schedules, and the pacing and concurrency reads. Standard library only; every call takes a context.Context.

It is a client, like camshaftctl. Workflows written in Go and served to the engine (docs/remote-protocol.md) are sdk/go/workflow's.

import camshaft "git.lunaor.com/lunaor/camshaft/sdk/go"

// The token source is asked before every call, so it can refresh an expiring Harpora token.
c := camshaft.NewClient("https://camshaft.example", camshaft.TokenFunc(func(ctx context.Context) (string, error) {
	return fetchHarporaToken(ctx)
}))

// Start a run of a flow (higher priority goes first among queued runs).
started, err := c.StartRun(ctx, camshaft.StartRun{Flow: "nightly", ID: "run-2026-12-02", Input: map[string]any{"customer": "acme"}, Priority: camshaft.Int(10)})
if started.Debounced && started.ID != "run-2026-12-02" {
	// collapsed into another run waiting out a debounce; no run exists under the id sent
}

run, err := c.GetRun(ctx, started.ID)               // the run and its journal
err = c.WatchRun(ctx, started.ID, func(e camshaft.RunEvent) bool { return true }) // status, live, end: to its end
page, err := c.ListRuns(ctx, camshaft.ListRuns{Status: camshaft.StatusFailed, Flow: "nightly", Limit: 50})
err = c.RetryRun(ctx, "run-1")                       // a failed run, its done steps kept
err = c.SignalRun(ctx, "run-1", "approve", true)
err = c.CancelRun(ctx, "run-1", "no longer needed")
_, err = c.SendEvent(ctx, "nightly", "paid", camshaft.Event{ID: "evt-1", Data: map[string]string{"customer": "acme"}})

Also: ListFlows, GetFlow, SaveFlow, DeleteFlow, RerunRun, EachRun (all pages), ListSchedules, SetSchedule, GetPacing and GetConcurrency.

Errors

A 4xx or 5xx is an *camshaft.APIError (status, the service's message, the daily Limit and RetryAfter of a 429). Test with the sentinels: errors.Is(err, camshaft.ErrNotFound), ErrConflict (409), ErrRateLimited (429), ErrForbidden, ErrBadRequest, ErrUnauthorized, ErrUnavailable.

A person's nod

Deleting a flow (and setting a schedule more often than every 5 minutes) needs a person's approval from Nod when the service has it on. The refusal is a *camshaft.NodError, carrying the issuer and the authorization_details to ask for; ask Nod (CIBA), then repeat the call with the approval token:

_, err := c.DeleteFlow(ctx, "nightly", "")
var nod *camshaft.NodError
if errors.As(err, &nod) {
	approval := askNod(ctx, nod.Issuer, nod.AuthorizationDetails) // your code: a person approves
	_, err = c.DeleteFlow(ctx, "nightly", approval)
}

Tests

go vet ./... && go test ./... runs against httptest stand-ins. One more test starts the real server: build it (cargo build -p camshaft-api --bin camshaft) and set CAMSHAFT_BIN to the binary and CAMSHAFT_PG to a PostgreSQL connection string for its store; without CAMSHAFT_BIN it is skipped.

CAMSHAFT_BIN=$PWD/../../target/debug/camshaft CAMSHAFT_PG=postgres://… go test ./...

Status: a first version (2026-12-02), not published. The module path is the repository's (git.lunaor.com/lunaor/camshaft/sdk/go). Publishing it (a tag, and any vanity path) is a person's step.

Workflows in Go

git.lunaor.com/lunaor/camshaft/sdk/go/workflow serves workflows written in Go to the engine over HTTP (docs/remote-protocol.md), as the TypeScript and Python SDKs do:

import "git.lunaor.com/lunaor/camshaft/sdk/go/workflow"

refund := func(c *workflow.Context, input json.RawMessage) (any, error) {
	amount, err := workflow.Step(c, "look up", func() (int, error) { return lookUp(input) }) // once, recorded
	if err != nil {
		return nil, err
	}
	ok, err := workflow.WaitSignal[bool](c, "approval", "approve") // waits for a person, durably
	if err != nil || !ok {
		return "declined", err
	}
	workflow.Sleep(c, "cool off", time.Minute) // durably
	return workflow.Step(c, "refund", func() (string, error) { return pay(input, amount) })
}
http.Handle("/camshaft", workflow.Handler(map[string]workflow.Workflow{"refund": refund}, os.Getenv("CAMSHAFT_SECRET")))

Also WaitSignalUntil (a deadline), Child (another workflow, any language; its failure is a *StepFailed), WaitUpdate with Answer or Refuse (an update's sender waits for the answer), and Publish (values read with GET /runs/{id}/published), and Tag (tags the run to find it by, GET /runs?tag=; key=value replaces its key). A step returning an error is retried by the engine; out of attempts, Step returns a *StepFailed (workflow.IsStepFailed(err)). The workflow runs from the top on each call and stops where the engine has to act, by a panic the handler recovers: workflow code must not recover panics it doesn't own. The rules are the protocol's: each name once per run, no side effects outside steps.