Skip to main content
The Go client is the runtime package github.com/bijectionhq/bijection/sdks/application/go/bijection plus a package that bijection client go generates from your app’s contract. The generated package names every exposed function as a typed ref and pins the contract, and the runtime runs the calls.

Install

The runtime uses only the standard library. It needs Go 1.22 or later.

Generate a client

--name is the module path. The command reads the app’s exposed tree and the contract line of the committed bijection.lock, and refuses when that line differs from the source’s (run bijection check --write-lock first). It writes: Generate the package again when the app’s exposed functions change. Do not edit it.

Connect

An installation whose contract differs from the pinned one refuses every call with Conflict, and the message starts with ContractStale. Generate the client again against the deployed app. For a dynamic tool, the raw connector uses bijection.Options{Discover: true}. A pinned client refuses a path absent from its contract map before sending it.

Calls

bijection.Query runs a query once. bijection.Mutate runs a mutation as one transaction:
bijection.Once names the one logical mutation. The same once and arguments answer the original result, and the same once with other arguments refuses Invalid. Without it the client mints one for the call. A mutation whose reply was lost answers Unknown: it may have committed. Ask again with the same once: An uncertain mutation carries its original request key in Result.Once.

Frames

As, Under, In and At return a client in that frame. The original client is unchanged.
A committed mutation’s result carries its Version. Pass it as bijection.Seen to read your own write:
The answer is then from state at least as new as that version.

Results

Every verb answers a bijection.Result[V]: A function’s declared codes (its refuses) arrive as the function refused them. Any other code the host answers is folded into its host code, and the message keeps the original code.

Watch

A watch delivers a Result each time the query’s value changes, over one live connection per frame. It reconnects on its own. Stop, or cancelling ctx, ends it. A watch from a client with In or At reads once and then ends.

Trial

bijection.Trial runs the call in a discarded world and commits nothing. It answers how the call would have ended (trial.Result, with Guard when a guard refused), the writes it would have made (Verb, Table, Key, Before, After) and the tasks it would have submitted (Target, Args, Due). ValidUntil is the instant the answer is valid until (a call at the same version committed before it is decided the same way), or nil when nothing time-dependent bounds it.

Values

A duration with years or months has no fixed length and does not fit time.Duration: decoding one fails.

Change entries

A query that returns a selection’s changes answers bijection.Change[T] entries: