Documentation
¶
Overview ¶
Package sov is the top-level façade for the sov framework. It re-exports the most-used types and constructors from sov/rpc, sov/gateway, and sov/signing so the 80% case can write `sov.X` against a single import.
import "github.com/Toyz/sov"
func main() {
gw := sov.New()
gw.Use(registry.New())
gw.Register(&MyRouter{})
log.Fatal(gw.ListenAndServe(ctx, ":8080"))
}
Power users who need transport adapters, mesh wiring, or the raw rpc.Engine reach for the underlying packages directly.
Index ¶
- Constants
- Variables
- func LoadEnv(paths ...string) error
- func LoadEnvOverride(paths ...string) error
- type AuthService
- type AuthzDecision
- type AuthzService
- type CheckParams
- type Claims
- type ClaimsCache
- type Client
- type ClientOption
- type Context
- type Error
- type Gateway
- type Handler
- type HybridConfig
- type MeshOptions
- type Middleware
- type MonolithConfig
- type Option
- type PodConfig
- type RegistryConfig
- type Request
- type Response
- type RoleFlag
- type VerifyParams
Constants ¶
const ( RoleAuth = gateway.RoleAuth RoleAuthz = gateway.RoleAuthz )
Variables ¶
var ( // New returns a Gateway. New = gateway.New // NewClient returns a Client that POSTs against baseURL. NewClient = gateway.NewClient // LocalRouters returns every wire-named router on gw — convenience // for team gateways that federate "everything I host". LocalRouters = gateway.LocalRouters // NormalizeUpstreamURL is the canonical form used by every // federation layer for identity comparisons. NormalizeUpstreamURL = gateway.NormalizeUpstreamURL // WithServer overrides the HTTP server. WithServer = gateway.WithServer // WithResolver overrides the resolver chain. WithResolver = gateway.WithResolver // WithMiddleware appends consumer middleware. WithMiddleware = gateway.WithMiddleware // WithProxyClient overrides the http.Client used for remote proxy. WithProxyClient = gateway.WithProxyClient // WithClaimsCache overrides the verified-claims cache (default // in-memory, per-replica). Pass a shared impl (e.g. Redis) so a fleet // of gateway replicas reuse each other's auth-verify results. WithClaimsCache = gateway.WithClaimsCache // WithTrustUpstreamClaims tells the default Server to trust inbound X-Sov-*. WithTrustUpstreamClaims = gateway.WithTrustUpstreamClaims // WithAdvertiseURL stamps the gateway's public URL on every outbound proxy hop as X-Sov-Upstream. WithAdvertiseURL = gateway.WithAdvertiseURL // WithHTTPClient overrides the underlying *http.Client for sov.NewClient. WithHTTPClient = gateway.WithHTTPClient // UseSigning wires the zero-trust signing middleware. UseSigning = signing.UseSigning // NewMonolith returns a gateway pre-loaded with preset.Monolith. NewMonolith = preset.NewMonolith // NewPod returns a gateway pre-loaded with preset.Pod. NewPod = preset.NewPod // NewRegistry returns a gateway pre-loaded with preset.Registry. NewRegistry = preset.NewRegistry // NewHybrid returns a gateway pre-loaded with preset.Hybrid. NewHybrid = preset.NewHybrid // HaltErr wraps an error so a boot-time hook refuses startup. HaltErr = gateway.HaltErr // RespondErr wraps an error with a *Response the gateway returns. RespondErr = gateway.RespondErr // IsHalt reports whether err carries a HaltErr sentinel. IsHalt = gateway.IsHalt )
var ( // RequireSubject extracts the authenticated subject id from ctx, or // returns 401 UNAUTHORIZED. The canonical handler-side gate. RequireSubject = rpc.RequireSubject // UserFromContext returns ctx.User or 401 UNAUTHORIZED. UserFromContext = rpc.UserFromContext // Common error constructors. NotFound = rpc.NotFound Forbidden = rpc.Forbidden ForbiddenCode = rpc.ForbiddenCode BadRequest = rpc.BadRequest BadRequestCode = rpc.BadRequestCode Conflict = rpc.Conflict Internal = rpc.Internal NotImplemented = rpc.NotImplemented TooManyRequests = rpc.TooManyRequests // Typed header accessors. ClaimsFromHeaders = gateway.ClaimsFromHeaders AuthorizationFromContext = gateway.AuthorizationFromContext )
Functions ¶
func LoadEnv ¶
LoadEnv reads each KEY=VALUE file at the supplied paths and calls os.Setenv for every entry. Missing files are skipped silently — useful for projects that ship .sov.env in dev but rely on real environment variables in production. Existing env vars are NOT overwritten (consistent with most .env conventions); call LoadEnvOverride when you want force.
func main() {
sov.LoadEnv(".sov.env")
gw := sov.NewMesh(...)
}
Wire shape: one entry per line. Lines beginning with '#' or empty lines are skipped. VALUE may be quoted with single or double quotes (quotes are stripped); inline `#` after an unquoted value starts a comment. No shell-style $VAR interpolation — values are literal.
func LoadEnvOverride ¶
LoadEnvOverride is LoadEnv with overwrite semantics — every parsed key replaces any existing env var. Use when the file is the source of truth and you want to reset stale values.
Types ¶
type AuthService ¶
type AuthService = gateway.AuthService
AuthService is the contract gw.RegisterAuth requires.
type AuthzDecision ¶
type AuthzDecision = gateway.AuthzDecision
AuthzDecision is the shape an AuthzService.Check must return.
type AuthzService ¶
type AuthzService = gateway.AuthzService
AuthzService is the contract gw.RegisterAuthz requires.
type CheckParams ¶
type CheckParams = gateway.CheckParams
CheckParams is what the gateway sends to AuthzService.Check.
type Claims ¶
Claims is the verified caller identity. Identity + delegation only — authorization state lives in the AuthzService.
type ClaimsCache ¶
type ClaimsCache = gateway.ClaimsCache
ClaimsCache is the verified-claims cache contract. Implement it (e.g. Redis-backed) and pass WithClaimsCache to share auth-verify results across gateway replicas. Default is in-memory, per-replica.
type Client ¶
Client is the cross-service caller interface. Either an in-process LocalClient or an HTTP-backed NewClient(baseURL).
type ClientOption ¶
type ClientOption = gateway.ClientOption
ClientOption mutates a gateway HTTP client constructed via NewClient.
type Gateway ¶
Gateway is the single entry point. Wraps a rpc.Engine + resolver chain behind a pluggable Server. See gateway.Gateway.
type HybridConfig ¶
type HybridConfig = preset.HybridConfig
Preset config type aliases — let consumers populate the preset configs without importing the preset package directly.
type Middleware ¶
type Middleware = gateway.Middleware
Middleware wraps the gateway's request handler.
type MonolithConfig ¶
type MonolithConfig = preset.MonolithConfig
Preset config type aliases — let consumers populate the preset configs without importing the preset package directly.
type PodConfig ¶
Preset config type aliases — let consumers populate the preset configs without importing the preset package directly.
type RegistryConfig ¶
type RegistryConfig = preset.RegistryConfig
Preset config type aliases — let consumers populate the preset configs without importing the preset package directly.
type VerifyParams ¶
type VerifyParams = gateway.VerifyParams
VerifyParams is what the gateway sends to AuthService.Verify.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
sov
command
sov — the sov gateway operator CLI.
|
sov — the sov gateway operator CLI. |
|
sov/call
Package call implements `sov call` — quick interactive RPC.
|
Package call implements `sov call` — quick interactive RPC. |
|
sov/conform
Package conform implements `sov conform` — validate that a running pod (in ANY language) satisfies the sov wire contract (docs/WIRE_CONTRACT.md).
|
Package conform implements `sov conform` — validate that a running pod (in ANY language) satisfies the sov wire contract (docs/WIRE_CONTRACT.md). |
|
sov/drift
Package drift implements `sov drift` — the drift-check subcommand.
|
Package drift implements `sov drift` — the drift-check subcommand. |
|
sov/gen
Package gen is the `sov gen` subcommand router.
|
Package gen is the `sov gen` subcommand router. |
|
sov/gen/all
Package all implements the `sov gen all` subcommand: fetch the gateway catalog once (or spawn the gateway binary once) and emit every supported language client into a single output directory.
|
Package all implements the `sov gen all` subcommand: fetch the gateway catalog once (or spawn the gateway binary once) and emit every supported language client into a single output directory. |
|
sov/gen/golang
Package golang implements the `sovgen go` subcommand.
|
Package golang implements the `sovgen go` subcommand. |
|
sov/gen/kotlin
Package kotlin implements the `sovgen kotlin` subcommand.
|
Package kotlin implements the `sovgen kotlin` subcommand. |
|
sov/gen/python
Package python implements the `sovgen python` subcommand.
|
Package python implements the `sovgen python` subcommand. |
|
sov/gen/swift
Package swift implements the `sovgen swift` subcommand.
|
Package swift implements the `sovgen swift` subcommand. |
|
sov/gen/ts
Package ts implements the `sov gen ts` subcommand.
|
Package ts implements the `sov gen ts` subcommand. |
|
sov/health
Package health implements `sov health` — pretty-print of the /rpc/_health rollup.
|
Package health implements `sov health` — pretty-print of the /rpc/_health rollup. |
|
sov/init_cmd
Package initcmd implements `sov init <mode>` — the project scaffolder.
|
Package initcmd implements `sov init <mode>` — the project scaffolder. |
|
sov/inspect
Package inspect implements `sov inspect` — pretty-print of the /rpc/_introspect catalog.
|
Package inspect implements `sov inspect` — pretty-print of the /rpc/_introspect catalog. |
|
sov/internal/catalog
Package catalog centralizes the shared sovgen plumbing: fetching a /rpc/_introspect report, spawning a gateway binary on a free local port, polling for readiness, and the repeated --header K=V flag type.
|
Package catalog centralizes the shared sovgen plumbing: fetching a /rpc/_introspect report, spawning a gateway binary on a free local port, polling for readiness, and the repeated --header K=V flag type. |
|
sov/internal/docgen
Package docgen renders the shared title/desc/doc/example/deprecated doc-comment block that every sovgen emitter attaches to generated types and fields.
|
Package docgen renders the shared title/desc/doc/example/deprecated doc-comment block that every sovgen emitter attaches to generated types and fields. |
|
sov/internal/output
Package output provides TTY-aware rendering helpers shared by the sov CLI subcommands that print to humans (drift, inspect, health).
|
Package output provides TTY-aware rendering helpers shared by the sov CLI subcommands that print to humans (drift, inspect, health). |
|
sov/internal/strs
Package strs holds the tiny string helpers the code emitters share.
|
Package strs holds the tiny string helpers the code emitters share. |
|
examples
|
|
|
chirp/cmd/hybrid
command
Hybrid binary: ONE gateway hosting Auth + Authz + User in-process while routing Chirp + Feed to remote pods registered via _register.
|
Hybrid binary: ONE gateway hosting Auth + Authz + User in-process while routing Chirp + Feed to remote pods registered via _register. |
|
chirp/cmd/mesh-tiered/chirps
command
Tiered mesh — chirps pod.
|
Tiered mesh — chirps pod. |
|
chirp/cmd/mesh-tiered/feed
command
Tiered mesh — feed pod.
|
Tiered mesh — feed pod. |
|
chirp/cmd/mesh-tiered/prime
command
Tiered mesh — master/prime gateway.
|
Tiered mesh — master/prime gateway. |
|
chirp/cmd/mesh-tiered/team-feed
command
Tiered mesh — team-feed gateway.
|
Tiered mesh — team-feed gateway. |
|
chirp/cmd/mesh-tiered/team-users
command
Tiered mesh — team-users gateway.
|
Tiered mesh — team-users gateway. |
|
chirp/cmd/mesh-tiered/users
command
Tiered mesh — users pod.
|
Tiered mesh — users pod. |
|
chirp/cmd/mesh/auth
command
Mesh pod: Auth service.
|
Mesh pod: Auth service. |
|
chirp/cmd/mesh/authz
command
Mesh pod: Authz service.
|
Mesh pod: Authz service. |
|
chirp/cmd/mesh/chirps
command
Mesh pod: Chirp service.
|
Mesh pod: Chirp service. |
|
chirp/cmd/mesh/feed
command
Mesh pod: Feed service.
|
Mesh pod: Feed service. |
|
chirp/cmd/mesh/gateway
command
Mesh-mode gateway: registry role only.
|
Mesh-mode gateway: registry role only. |
|
chirp/cmd/mesh/users
command
Mesh pod: User service.
|
Mesh pod: User service. |
|
chirp/cmd/monolith
command
Monolith binary: gateway + all chirp services + the authz policy in one process.
|
Monolith binary: gateway + all chirp services + the authz policy in one process. |
|
chirp/cmd/nested-pemm
command
Nested PEMM: TWO gateways in ONE binary linked via localpeer.
|
Nested PEMM: TWO gateways in ONE binary linked via localpeer. |
|
chirp/handlers/auth
Package auth is the chirp demo's identity surface — register a credential, exchange a handle+password for a session token, verify tokens for the gateway.
|
Package auth is the chirp demo's identity surface — register a credential, exchange a handle+password for a session token, verify tokens for the gateway. |
|
chirp/handlers/authz
Package authz is the chirp demo's policy-as-service.
|
Package authz is the chirp demo's policy-as-service. |
|
chirp/handlers/chirps
Package chirps owns the chirp entity end-to-end.
|
Package chirps owns the chirp entity end-to-end. |
|
chirp/handlers/feed
Package feed assembles a user's timeline by calling UserService for the follow graph and ChirpService for the chirps.
|
Package feed assembles a user's timeline by calling UserService for the follow graph and ChirpService for the chirps. |
|
chirp/handlers/users
Package users owns the user identity + follow graph end-to-end.
|
Package users owns the user identity + follow graph end-to-end. |
|
minimal
command
Minimal sov example: one Echo service, one binary, ~10 lines of wiring.
|
Minimal sov example: one Echo service, one binary, ~10 lines of wiring. |
|
Package gateway is the entry point that wraps a sov rpc.Engine and exposes it over an HTTP-shaped server.
|
Package gateway is the entry point that wraps a sov rpc.Engine and exposes it over an HTTP-shaped server. |
|
builtin/audit
Package audit ships a sov plugin that records every dispatch event into a sliding-window in-memory ring AND emits structured JSON to a writer (typically os.Stdout or a log file).
|
Package audit ships a sov plugin that records every dispatch event into a sliding-window in-memory ring AND emits structured JSON to a writer (typically os.Stdout or a log file). |
|
builtin/auth
Package auth ships a first-party sov plugin that translates verified Claims into legacy-shape headers ("X-Forwarded-User" / "X-Forwarded-Scopes" / "X-Tenant-Id") on every outbound proxy hop.
|
Package auth ships a first-party sov plugin that translates verified Claims into legacy-shape headers ("X-Forwarded-User" / "X-Forwarded-Scopes" / "X-Tenant-Id") on every outbound proxy hop. |
|
builtin/batch
Package batch ships the cascading-batch endpoint at /rpc/_batch.
|
Package batch ships the cascading-batch endpoint at /rpc/_batch. |
|
builtin/cors
Package cors adds CORS headers to every response and handles the browser's OPTIONS preflight short-circuit.
|
Package cors adds CORS headers to every response and handles the browser's OPTIONS preflight short-circuit. |
|
builtin/explorer
Package explorer mounts the embedded HTML browser at /rpc/_explorer/.
|
Package explorer mounts the embedded HTML browser at /rpc/_explorer/. |
|
builtin/hmacseal
Package hmacseal seals injected X-Sov-* claim headers with HMAC-SHA256 so downstream services can detect forged claim bundles.
|
Package hmacseal seals injected X-Sov-* claim headers with HMAC-SHA256 so downstream services can detect forged claim bundles. |
|
builtin/hmacseal/proto
Package proto is the wire format for X-Sov-Seal.
|
Package proto is the wire format for X-Sov-Seal. |
|
builtin/introspect
Package introspect is the opt-in plugin that exposes the public /rpc/_introspect endpoint — the aggregated API catalog (every service, method, and type the gateway can route).
|
Package introspect is the opt-in plugin that exposes the public /rpc/_introspect endpoint — the aggregated API catalog (every service, method, and type the gateway can route). |
|
builtin/manifest
Package manifest emits the PEMM manifest of a running gateway — a single JSON document describing services, plugins, role bindings, federation map, and registered remotes.
|
Package manifest emits the PEMM manifest of a running gateway — a single JSON document describing services, plugins, role bindings, federation map, and registered remotes. |
|
builtin/meshsecret
Package meshsecret ships the HMAC gate for /rpc/_register.
|
Package meshsecret ships the HMAC gate for /rpc/_register. |
|
builtin/meshsecret/proto
Package proto is the wire format for the mesh-secret-gated /rpc/_register sig.
|
Package proto is the wire format for the mesh-secret-gated /rpc/_register sig. |
|
builtin/metrics
Package metrics ships a Prometheus-text-format metrics plugin for sov.
|
Package metrics ships a Prometheus-text-format metrics plugin for sov. |
|
builtin/preempt
Package preempt permits a federated _register to take over a service name already claimed by a different address.
|
Package preempt permits a federated _register to take over a service name already claimed by a different address. |
|
builtin/registertoken
Package registertoken ships the simple shared-token gate for /rpc/_register.
|
Package registertoken ships the simple shared-token gate for /rpc/_register. |
|
builtin/registertoken/proto
Package proto is the wire format for the static register-token join gate.
|
Package proto is the wire format for the static register-token join gate. |
|
builtin/registry
Package registry promotes the gateway to central-registry shape — owns POST /rpc/_register and the public top-level /health URL.
|
Package registry promotes the gateway to central-registry shape — owns POST /rpc/_register and the public top-level /health URL. |
|
builtin/requestid
Package requestid stamps a stable X-Sov-Request-Id on every request as it enters the gateway and propagates it through every hop the request takes: outbound proxy calls, in-process local dispatch, and downstream gateways (via the same header).
|
Package requestid stamps a stable X-Sov-Request-Id on every request as it enters the gateway and propagates it through every hop the request takes: outbound proxy calls, in-process local dispatch, and downstream gateways (via the same header). |
|
builtin/roletakeover
Package roletakeover relaxes the default cross-name role-binding guard.
|
Package roletakeover relaxes the default cross-name role-binding guard. |
|
builtin/static
Package static mounts a static-file tree (a built SPA, a docs site, a bundle of assets) on the gateway via a RouteHandler.
|
Package static mounts a static-file tree (a built SPA, a docs site, a bundle of assets) on the gateway via a RouteHandler. |
|
builtin/upstreams
Package upstreams limits which upstream gateway URLs a pod trusts X-Sov-* claim headers from.
|
Package upstreams limits which upstream gateway URLs a pod trusts X-Sov-* claim headers from. |
|
preset
Package preset curates default plugin bundles for the common sov deployment modes.
|
Package preset curates default plugin bundles for the common sov deployment modes. |
|
Package rpc is the transport-agnostic controller layer for Sov.
|
Package rpc is the transport-agnostic controller layer for Sov. |
|
tsrender
Package tsrender turns Go reflect types into TypeScript-shaped strings.
|
Package tsrender turns Go reflect types into TypeScript-shaped strings. |
|
Package rpctest is the test-ergonomics helper for sov consumers.
|
Package rpctest is the test-ergonomics helper for sov consumers. |
|
Package signing implements Sov's per-request Ed25519 request-signing scheme.
|
Package signing implements Sov's per-request Ed25519 request-signing scheme. |