routecontracts

package
v3.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package routecontracts registers HTTP routes and OpenAPI operations together.

It is intentionally router-neutral and uses only the common method registration shape already provided by ports.HTTPRouter. PATCH support is detected with a local optional interface so stable router interfaces are not widened.

Registered routes automatically attach bounded routepolicy observability labels to the request context so outer metrics and request logging middleware can record policy shape without seeing raw scopes, tenants, or policy names.

Package routecontracts keeps runtime route registration and OpenAPI operation registration in one place.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CoverageError

type CoverageError struct {
	Problems []string
}

CoverageError describes a route-contract coverage problem.

func (CoverageError) Error

func (err CoverageError) Error() string

Error returns a human-readable error.

type Options

type Options struct {
	Policies []Policy
}

Options configures Registry behavior.

type Policy

type Policy interface {
	Apply(specs.Operation) (specs.Operation, []func(http.Handler) http.Handler, error)
}

Policy derives automatic middleware and operation metadata from a route operation.

type PolicyFunc

type PolicyFunc func(specs.Operation) (specs.Operation, []func(http.Handler) http.Handler, error)

PolicyFunc adapts a function to Policy.

func (PolicyFunc) Apply

func (f PolicyFunc) Apply(operation specs.Operation) (specs.Operation, []func(http.Handler) http.Handler, error)

Apply derives middleware and operation metadata from an operation.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry registers runtime routes and matching OpenAPI operations.

func NewRegistry

func NewRegistry(router Router, specRegistry *specs.Registry) *Registry

NewRegistry constructs a registry with default behavior.

func NewRegistryWithOptions

func NewRegistryWithOptions(router Router, specRegistry *specs.Registry, opts Options) *Registry

NewRegistryWithOptions constructs a registry with policy options.

func (*Registry) Delete

func (registry *Registry) Delete(pattern string, operation specs.Operation, handler http.Handler, middleware ...func(http.Handler) http.Handler) error

Delete registers a DELETE route.

func (*Registry) Get

func (registry *Registry) Get(pattern string, operation specs.Operation, handler http.Handler, middleware ...func(http.Handler) http.Handler) error

Get registers a GET route.

func (*Registry) Patch

func (registry *Registry) Patch(pattern string, operation specs.Operation, handler http.Handler, middleware ...func(http.Handler) http.Handler) error

Patch registers a PATCH route when the router supports Patch.

func (*Registry) Post

func (registry *Registry) Post(pattern string, operation specs.Operation, handler http.Handler, middleware ...func(http.Handler) http.Handler) error

Post registers a POST route.

func (*Registry) Put

func (registry *Registry) Put(pattern string, operation specs.Operation, handler http.Handler, middleware ...func(http.Handler) http.Handler) error

Put registers a PUT route.

func (*Registry) Register

func (registry *Registry) Register(route Route) error

Register registers a route and matching operation.

func (*Registry) Routes

func (registry *Registry) Routes() []Route

Routes returns the registered routes in deterministic order.

func (*Registry) Validate

func (registry *Registry) Validate() error

Validate verifies registered routes have matching operations.

type Route

type Route struct {
	Method     string
	Pattern    string
	Handler    http.Handler
	Middleware []func(http.Handler) http.Handler
	Operation  specs.Operation
}

Route binds an HTTP route to its OpenAPI operation.

type Router

type Router interface {
	Get(pattern string, h http.HandlerFunc)
	Post(pattern string, h http.HandlerFunc)
	Put(pattern string, h http.HandlerFunc)
	Delete(pattern string, h http.HandlerFunc)
}

Router is the minimal router contract used by Registry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL