go.varianz.io/sdk, imported as go.varianz.io/sdk/varianz (install). The test-side package varianztest is covered in Testing → Go.
vz.Init() and defer vz.Close() in main() are required — without Init(), VPoints don’t connect to the registry. When the SDK is disabled, varianz.VPoint returns your original function unchanged and every registration call succeeds as a no-op.
Defining VPoints
varianz.VPoint is a typed higher-order wrapper: it registers the function and returns a callable with the same signature.
- The signature is
func(context.Context, Req) (Resp, error)— exactly one input parameter besides the context. Group multiple arguments into a struct. Req/Respcan be structs, primitives, or proto messages (pointer types included).- Use struct type names directly in CEL (
PricingResponse, notpb.PricingResponse). Nested proto messages construct fine in CEL literals — no flattening needed.
Where to declare
Three equivalent patterns — there is no rule that VPoints must be package-level:-
Package-level
var(above) — simplest for standalone functions. -
Service struct +
vz.Register— most idiomatic for dependency-injected services:Every exported method becomes a VPoint, named PascalCase → kebab-case with thevarianztag as prefix (CalculatePrice→pricing/calculate-price; acronyms group:HTTPSPort→https-port). -
Wrap a bound method —
varianz.VPoint(vz, name, svc.CalculatePrice)when you want a typed package-level callable that still captures instance state.
varianz-gen you get typed proxies instead of proxy.Call’s any returns.
Sessions
The session rides oncontext.Context:
varianz.VPoint callables and proxy.Call extract it automatically. Interceptor and middleware snippets: Propagate sessions. Never start a goroutine without passing the parent context.
Field names
Schema field names resolve in priority order:varianz:"name"tag — explicit overrideprotobuftag — proto canonical namejson:"name"tag — covers oapi-codegen, sqlc, gqlgen, and similar codegen outputtoSnakeCase(GoName)— untagged fallback (BasePrice→base_price)
chan, func, or unsafe.Pointer. Proto-internal fields (state, sizeCache, unknownFields) are skipped automatically.
Context functions
ctx.applyTax(...).
Troubleshooting
go test -tags=integrationfails with vet errors in upstream code — the integration tag pulls files into the build that surface pre-existinggo vetwarnings (commonlystatus.Errorf(codes.Internal, err.Error())). Fix upstream with an explicit"%s", or run with-vet=off.- Vendored builds drop the SDK —
-mod=vendorneeds bothvendor/go.varianz.io/sdk/and thevendor/modules.txtentry. Re-rungo mod vendorafter upgrading; don’t hand-copy. - Link errors or missing symbols in Docker — you built with
CGO_ENABLED=0or astatic/scratchruntime image. See the Docker pattern.
