Skip to main content
The Go application SDK is module 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.
Rules:
  • The signature is func(context.Context, Req) (Resp, error) — exactly one input parameter besides the context. Group multiple arguments into a struct.
  • Req/Resp can be structs, primitives, or proto messages (pointer types included).
  • Use struct type names directly in CEL (PricingResponse, not pb.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:
  1. Package-level var (above) — simplest for standalone functions.
  2. Service struct + vz.Register — most idiomatic for dependency-injected services:
    Every exported method becomes a VPoint, named PascalCase → kebab-case with the varianz tag as prefix (CalculatePricepricing/calculate-price; acronyms group: HTTPSPorthttps-port).
  3. Wrap a bound methodvarianz.VPoint(vz, name, svc.CalculatePrice) when you want a typed package-level callable that still captures instance state.
With varianz-gen you get typed proxies instead of proxy.Call’s any returns.

Sessions

The session rides on context.Context:
Both 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:
  1. varianz:"name" tag — explicit override
  2. protobuf tag — proto canonical name
  3. json:"name" tag — covers oapi-codegen, sqlc, gqlgen, and similar codegen output
  4. toSnakeCase(GoName) — untagged fallback (BasePricebase_price)
Registration validates struct types and fails with a clear error for structs with no exported fields or fields of type chan, func, or unsafe.Pointer. Proto-internal fields (state, sizeCache, unknownFields) are skipped automatically.

Context functions

Available in CEL as ctx.applyTax(...).

Troubleshooting

  • go test -tags=integration fails with vet errors in upstream code — the integration tag pulls files into the build that surface pre-existing go vet warnings (commonly status.Errorf(codes.Internal, err.Error())). Fix upstream with an explicit "%s", or run with -vet=off.
  • Vendored builds drop the SDK-mod=vendor needs both vendor/go.varianz.io/sdk/ and the vendor/modules.txt entry. Re-run go mod vendor after upgrading; don’t hand-copy.
  • Link errors or missing symbols in Docker — you built with CGO_ENABLED=0 or a static/scratch runtime image. See the Docker pattern.