Documentation
¶
Overview ¶
Package protoregistry provides a multi-namespace protobuf schema registry with versioning, staging, and hot-swap capabilities.
It uses protocompile to compile .proto source files at runtime, stores versioned schemas in Postgres with content-addressable deduplication, and serves compiled descriptors for dynamic message creation and validation.
Each namespace is an isolated scope — proto imports resolve only within the same namespace, similar to a chroot. Schemas within a namespace are versioned independently, with a staging mechanism for coordinated multi-schema promotions.
Index ¶
- Constants
- type Option
- type PromoteResult
- type PublishRequest
- type PublishResult
- type Registry
- func (r *Registry) Current(namespaceID, schemaID string) *snapshot.Snapshot
- func (r *Registry) DiscardStaging(ctx context.Context, namespaceID string) error
- func (r *Registry) Namespaces() *namespace.Registry
- func (r *Registry) Promote(ctx context.Context, namespaceID string) (*PromoteResult, error)
- func (r *Registry) Publish(ctx context.Context, req *PublishRequest) (*PublishResult, error)
- func (r *Registry) Restore(ctx context.Context) error
- func (r *Registry) Rollback(ctx context.Context, namespaceID, schemaID string, version uint64, ...) error
- func (r *Registry) Staged(namespaceID, schemaID string) *snapshot.Snapshot
- type RollbackOptions
Constants ¶
const BuiltinsNamespace = "__builtins__"
BuiltinsNamespace is the reserved namespace for built-in proto files. Schemas published here are available to all namespaces during compilation.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Registry)
Option configures a Registry.
func WithCompiler ¶
WithCompiler sets a custom compiler for the registry.
type PromoteResult ¶
type PromoteResult struct {
Promoted []store.PromotedSchema
}
PromoteResult contains the outcome of a promote operation.
type PublishRequest ¶
type PublishRequest struct {
NamespaceID string
SchemaID string
Sources map[string][]byte // filename → proto source content
CreatedBy string
Metadata map[string]string
Force bool // when true, allows publishing files that shadow well-known types
}
PublishRequest contains the parameters for publishing a new schema version.
type PublishResult ¶
type PublishResult struct {
Version uint64
Fingerprint string
Snapshot *snapshot.Snapshot
NoChange bool // true if the content is identical to the current staged/current version
}
PublishResult contains the outcome of a publish operation.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the top-level orchestrator that ties together compilation, storage, namespace management, and compatibility checking.
func (*Registry) DiscardStaging ¶
DiscardStaging clears all staged versions in a namespace without promoting.
func (*Registry) Namespaces ¶
Namespaces returns the namespace registry for direct access.
func (*Registry) Promote ¶
Promote atomically moves all staged versions to current within a namespace. Before promoting, it runs backward compatibility checks on each staged schema against its current version.
func (*Registry) Publish ¶
func (r *Registry) Publish(ctx context.Context, req *PublishRequest) (*PublishResult, error)
Publish compiles new proto sources and stages the result. The new version is not yet visible to consumers — call Promote to make it current.
The compilation resolves imports against the namespace's proposed state (staged versions where they exist, current otherwise), enabling coordinated multi-schema changes.
func (*Registry) Restore ¶
Restore loads all current schema versions from the store and rebuilds the in-memory namespace state. Call this at startup.
func (*Registry) Rollback ¶
func (r *Registry) Rollback(ctx context.Context, namespaceID, schemaID string, version uint64, opts RollbackOptions) error
Rollback stages a previous version of a schema for promotion.
Unless opts.Force is set, Rollback runs the same compat check as a forward Publish, treating the current version as "old" and the target version as "new". This catches the common screw-up of rolling back to a release that lacks API surface (fields, methods, enum values) added in the meantime, which would silently break consumers when the rollback is promoted.
The version must already exist in the store.
type RollbackOptions ¶
type RollbackOptions struct {
// Force bypasses the API-compat check that would otherwise reject a
// rollback whose target is not backward-compatible with the current
// version. Use sparingly: skipping the check shifts the cost to
// downstream consumers, who may break unexpectedly when the rollback
// is promoted.
Force bool
}
RollbackOptions configures a Rollback call.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client provides a remote-backed protobuf descriptor resolver that fetches schemas from a running protoregistry server over gRPC.
|
Package client provides a remote-backed protobuf descriptor resolver that fetches schemas from a running protoregistry server over gRPC. |
|
internal/clienttest
Package clienttest is a test-only harness that wires a real protoregistry server (Postgres + gRPC over bufconn) and exposes a *grpc.ClientConn ready to be passed to client.New, plus helpers for the publish/promote dance.
|
Package clienttest is a test-only harness that wires a real protoregistry server (Postgres + gRPC over bufconn) and exposes a *grpc.ClientConn ready to be passed to client.New, plus helpers for the publish/promote dance. |
|
cmd
|
|
|
protoregistry
command
|
|
|
Package compat checks backward compatibility between schema versions.
|
Package compat checks backward compatibility between schema versions. |
|
Package compiler wraps protocompile to provide namespace-scoped compilation of proto source files.
|
Package compiler wraps protocompile to provide namespace-scoped compilation of proto source files. |
|
internal
|
|
|
ctl
Package ctl implements the protoregistry CLI commands.
|
Package ctl implements the protoregistry CLI commands. |
|
Package migrations embeds the SQL migration files for use by goose.
|
Package migrations embeds the SQL migration files for use by goose. |
|
Package namespace provides the isolation boundary for schemas.
|
Package namespace provides the isolation boundary for schemas. |
|
proto
|
|
|
Package resolve bridges the protoregistry namespace snapshots with protobuf-go's protoregistry types, enabling runtime type resolution for external consumers.
|
Package resolve bridges the protoregistry namespace snapshots with protobuf-go's protoregistry types, enabling runtime type resolution for external consumers. |
|
Package server implements the gRPC RegistryService.
|
Package server implements the gRPC RegistryService. |
|
Package snapshot provides immutable, compiled descriptor sets that are safe for concurrent access.
|
Package snapshot provides immutable, compiled descriptor sets that are safe for concurrent access. |
|
Package store defines the persistence interface for the schema registry.
|
Package store defines the persistence interface for the schema registry. |
|
postgres
Package postgres implements the store.Store interface using PostgreSQL with sqlc-generated query code and pgx as the driver.
|
Package postgres implements the store.Store interface using PostgreSQL with sqlc-generated query code and pgx as the driver. |
|
postgres/pgtest
Package pgtest provides a shared test helper for spinning up a PostgreSQL container with migrations applied.
|
Package pgtest provides a shared test helper for spinning up a PostgreSQL container with migrations applied. |