routecontracts

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 6 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.

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 reports route contract validation failures.

func (*CoverageError) Error

func (e *CoverageError) Error() string

type Registry

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

Registry registers routes and keeps route contract metadata for validation.

func NewRegistry

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

NewRegistry creates a route contract registry.

func (*Registry) Delete

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

Delete registers a DELETE route contract.

func (*Registry) Get

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

Get registers a GET route contract.

func (*Registry) Patch

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

Patch registers a PATCH route contract when the router supports PATCH.

func (*Registry) Post

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

Post registers a POST route contract.

func (*Registry) Put

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

Put registers a PUT route contract.

func (*Registry) Register

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

Register registers a route handler and matching OpenAPI operation.

func (*Registry) Routes

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

Routes returns registered route contracts in deterministic method/path order.

func (*Registry) Validate

func (r *Registry) Validate() error

Validate checks for duplicate or incomplete route contracts.

type Route

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

Route describes one runtime route and 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 route registration surface required by this package.

Jump to

Keyboard shortcuts

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