nethttpadapter

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package nethttpadapter mounts routes on a net/http ServeMux while recording each route's contract in an goenax.Registry — one declaration, two outputs.

It relies on the Go 1.22+ ServeMux, whose patterns carry the method ("POST /path"). Like the Echo adapter, goenax's core stays framework-neutral; this file is the only part that knows about net/http.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is the standard net/http middleware shape.

type Router

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

Router wraps a ServeMux and a registry, prepending prefix to recorded paths.

func New

func New(mux *http.ServeMux, reg *goenax.Registry, prefix string) *Router

New wraps a ServeMux together with the registry. prefix is prepended to every recorded path (e.g. "/api") so the registry holds absolute paths.

func (*Router) DELETE

func (r *Router) DELETE(path string, h http.HandlerFunc, opts []goenax.Option, mw ...Middleware)

DELETE mounts and records a DELETE route.

func (*Router) Docs added in v0.2.0

func (r *Router) Docs(path string, docs http.Handler, mw ...Middleware)

Docs mounts a goenax.Docs handler at path and path+"/" (the UI) and path+"/openapi.json" (the spec). The docs routes are not recorded in the spec and are ignored by Coverage. Pass middleware to guard them, e.g. auth in production:

api.Docs("/docs", goenax.Docs(reg, info), requireStaff)

func (*Router) GET

func (r *Router) GET(path string, h http.HandlerFunc, opts []goenax.Option, mw ...Middleware)

GET mounts and records a GET route.

func (*Router) Handle

func (r *Router) Handle(
	method, path string,
	h http.HandlerFunc,
	opts []goenax.Option,
	mw ...Middleware,
)

Handle mounts a route on the mux (as "METHOD /prefix/path") and records its contract. Middleware is applied outermost-first.

func (*Router) PATCH added in v0.2.0

func (r *Router) PATCH(path string, h http.HandlerFunc, opts []goenax.Option, mw ...Middleware)

PATCH mounts and records a PATCH route.

func (*Router) POST

func (r *Router) POST(path string, h http.HandlerFunc, opts []goenax.Option, mw ...Middleware)

POST mounts and records a POST route.

func (*Router) PUT added in v0.2.0

func (r *Router) PUT(path string, h http.HandlerFunc, opts []goenax.Option, mw ...Middleware)

PUT mounts and records a PUT route.

Jump to

Keyboard shortcuts

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