chi

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GoForge Chi migration facade

goforge.dev/gpchi is a bounded compatibility facade for github.com/go-chi/chi/v5 v5.3.1 (8b258c7bb28f97a5f2a856ff7ef962578fec9215, MIT).

Registration looks familiar, but Compile produces an immutable route snapshot with structured conflict diagnostics and flat RouteInfo metadata. Exact routes are directly indexed; dynamic routes are parsed once and ordered deterministically. Snapshot.Resolve returns exhaustive matched, method-mismatch, or missing outcomes. The snapshot is also an ordinary net/http.Handler.

The router and middleware are authored in 14 .gp files. MatchOutcome is a Go+ enum, so semantic resolution is exhaustive in authored code while the generated variants remain usable from ordinary Go. Checked *_gp.go files are reproducible build artifacts:

go generate ./...
go tool goplus gen -check ./...

The Go+-authored std/http/route layer adds Pattern[p], Request[p], ParamKey[T,p], Handler[p], indexed route sets, and capability-indexed middleware. Mux.Typed and Mux.UseCapability are the migration bridges.

See COMPATIBILITY.md, PERFORMANCE.md, and the reproducible API_MANIFEST.csv. The corrected inventory contains 127 consumer-nameable declarations: all 127 declarations are implemented with zero deferred manifest rows. Behavioral and performance release gates remain open. The implementation is independently structured; no upstream implementation source was copied. UPSTREAM_LICENSE preserves Chi's copyright and MIT notice.

Reproduce the inventory

upstream_root=$(go env GOMODCACHE)/github.com/go-chi/chi/v5@v5.3.1
go run ./internal/cmd/apimanifest "$upstream_root" API_MANIFEST.csv

Documentation

Overview

Package chi provides a Go+-authored, bounded Chi-compatible registration facade backed by immutable compiled route snapshots.

Index

Constants

This section is empty.

Variables

View Source
var RouteCtxKey = &contextKey{name: "RouteContext"}

Functions

func Fold

func Fold[R any](m MatchOutcome, cs MatchOutcomeCases[R]) R

Fold reduces MatchOutcome by one-level case analysis.

func RegisterMethod

func RegisterMethod(method string)

func URLParam

func URLParam(r *http.Request, key string) string

func URLParamFromCtx

func URLParamFromCtx(ctx context.Context, key string) string

func Walk

func Walk(r Routes, walkFn WalkFunc) error

Types

type ChainHandler

type ChainHandler struct {
	Endpoint http.Handler

	Middlewares Middlewares
	// contains filtered or unexported fields
}

func (*ChainHandler) ServeHTTP

func (handler *ChainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Conflict

type Conflict struct {
	Kind   ConflictKind
	Method string
	Left   string
	Right  string
}

func (Conflict) Error

func (c Conflict) Error() string

type ConflictKind

type ConflictKind uint8
const (
	DuplicateRoute ConflictKind = iota + 1
	AmbiguousRoute
)

type Context

type Context struct {
	Routes        Routes
	RoutePath     string
	RouteMethod   string
	URLParams     RouteParams
	RoutePatterns []string
	// contains filtered or unexported fields
}

func NewRouteContext

func NewRouteContext() *Context

func RouteContext

func RouteContext(ctx context.Context) *Context

func (*Context) Reset

func (x *Context) Reset()

func (*Context) RoutePattern

func (x *Context) RoutePattern() string

func (*Context) URLParam

func (x *Context) URLParam(key string) string

type MatchOutcome

type MatchOutcome interface {
	// contains filtered or unexported methods
}

MatchOutcome is the exhaustive Go+ semantic lookup result. Compatibility Match remains boolean, while new code must distinguish a route match, a method mismatch, and an absent route without executing a handler.

type MatchOutcomeCases

type MatchOutcomeCases[R any] struct {
	MatchedRoute   func(Route RouteInfo, Params map[string]string) R
	MethodMismatch func(Allowed []string) R
	RouteMissing   func() R
}

MatchOutcomeCases selects one handler per MatchOutcome variant for Fold.

type MatchedRoute

type MatchedRoute struct {
	Route  RouteInfo
	Params map[string]string
}

type MethodMismatch

type MethodMismatch struct {
	Allowed []string
}

type Middlewares

type Middlewares []func(http.Handler) http.Handler

func Chain

func Chain(middlewares ...func(http.Handler) http.Handler) Middlewares

func NewChain

func NewChain(middlewares ...func(http.Handler) http.Handler) Middlewares

func (Middlewares) Handler

func (middlewares Middlewares) Handler(handler http.Handler) http.Handler

func (Middlewares) HandlerFunc

func (middlewares Middlewares) HandlerFunc(handler http.HandlerFunc) http.Handler

type Mux

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

func NewMux

func NewMux() *Mux

func NewRouter

func NewRouter() *Mux

func (*Mux) Compile

func (m *Mux) Compile() (*Snapshot, []Conflict)

func (*Mux) Connect

func (m *Mux) Connect(p string, h http.HandlerFunc)

func (*Mux) Delete

func (m *Mux) Delete(p string, h http.HandlerFunc)

func (*Mux) Find

func (m *Mux) Find(ctx *Context, method, path string) string

func (*Mux) Get

func (m *Mux) Get(p string, h http.HandlerFunc)

func (*Mux) Group

func (m *Mux) Group(fn func(Router)) Router

func (*Mux) Handle

func (m *Mux) Handle(pattern string, handler http.Handler)

func (*Mux) HandleFunc

func (m *Mux) HandleFunc(pattern string, handler http.HandlerFunc)

func (*Mux) Head

func (m *Mux) Head(p string, h http.HandlerFunc)

func (*Mux) Match

func (m *Mux) Match(ctx *Context, method, path string) bool

func (*Mux) Method

func (m *Mux) Method(method, pattern string, handler http.Handler)

func (*Mux) MethodFunc

func (m *Mux) MethodFunc(method, pattern string, handler http.HandlerFunc)

func (*Mux) MethodNotAllowed

func (m *Mux) MethodNotAllowed(handler http.HandlerFunc)

func (*Mux) MethodNotAllowedHandler

func (m *Mux) MethodNotAllowedHandler() http.HandlerFunc

MethodNotAllowedHandler returns the configured 405 handler or Chi's default zero-argument responder. Upstream's variadic element type is private, so external consumers can only call the public method without arguments.

func (*Mux) Middlewares

func (m *Mux) Middlewares() Middlewares

func (*Mux) Mount

func (m *Mux) Mount(pattern string, handler http.Handler)

func (*Mux) NotFound

func (m *Mux) NotFound(handler http.HandlerFunc)

func (*Mux) NotFoundHandler

func (m *Mux) NotFoundHandler() http.HandlerFunc

func (*Mux) Options

func (m *Mux) Options(p string, h http.HandlerFunc)

func (*Mux) Patch

func (m *Mux) Patch(p string, h http.HandlerFunc)

func (*Mux) Post

func (m *Mux) Post(p string, h http.HandlerFunc)

func (*Mux) Put

func (m *Mux) Put(p string, h http.HandlerFunc)

func (*Mux) Query

func (m *Mux) Query(p string, h http.HandlerFunc)

func (*Mux) Route

func (m *Mux) Route(pattern string, fn func(Router)) Router

func (*Mux) Routes

func (m *Mux) Routes() []Route

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Mux) Trace

func (m *Mux) Trace(p string, h http.HandlerFunc)

func (*Mux) Typed

func (m *Mux) Typed(method string, pattern stdroute.Pattern, handler stdroute.Handler)

Typed registers the Go+-authored pattern-indexed handler boundary. Go+ statically requires the handler and its parameter keys to share the pattern index; this facade consumes the erased ordinary-Go handler.

func (*Mux) Use

func (m *Mux) Use(middlewares ...func(http.Handler) http.Handler)

func (*Mux) UseCapability

func (m *Mux) UseCapability(middleware stdroute.Middleware)

UseCapability consumes capability-indexed Go+ middleware at the ordinary-Go compatibility boundary.

func (*Mux) With

func (m *Mux) With(middlewares ...func(http.Handler) http.Handler) Router

type Route

type Route struct {
	SubRoutes Routes
	Handlers  map[string]http.Handler
	Pattern   string
}

type RouteInfo

type RouteInfo struct {
	Method     string
	Pattern    string
	ParamNames []string
	Handler    http.Handler
	SubRoutes  Routes
}

RouteInfo is immutable flat metadata for documentation and OpenAPI generation without traversing private router nodes.

type RouteMissing

type RouteMissing struct{}

type RouteParams

type RouteParams struct{ Keys, Values []string }

func (*RouteParams) Add

func (s *RouteParams) Add(key, value string)

type Router

type Router interface {
	http.Handler
	Routes
	Use(...func(http.Handler) http.Handler)
	With(...func(http.Handler) http.Handler) Router
	Group(func(Router)) Router
	Route(string, func(Router)) Router
	Mount(string, http.Handler)
	Handle(string, http.Handler)
	HandleFunc(string, http.HandlerFunc)
	Method(string, string, http.Handler)
	MethodFunc(string, string, http.HandlerFunc)
	Connect(string, http.HandlerFunc)
	Delete(string, http.HandlerFunc)
	Get(string, http.HandlerFunc)
	Head(string, http.HandlerFunc)
	Options(string, http.HandlerFunc)
	Patch(string, http.HandlerFunc)
	Post(string, http.HandlerFunc)
	Put(string, http.HandlerFunc)
	Query(string, http.HandlerFunc)
	Trace(string, http.HandlerFunc)
	NotFound(http.HandlerFunc)
	MethodNotAllowed(http.HandlerFunc)
}

type Routes

type Routes interface {
	Routes() []Route
	Middlewares() Middlewares
	Match(*Context, string, string) bool
	Find(*Context, string, string) string
}

type Snapshot

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

func (*Snapshot) Find

func (s *Snapshot) Find(ctx *Context, method, path string) string

func (*Snapshot) Match

func (s *Snapshot) Match(ctx *Context, method, path string) bool

func (*Snapshot) Metadata

func (s *Snapshot) Metadata() []RouteInfo

func (*Snapshot) Middlewares

func (s *Snapshot) Middlewares() Middlewares

func (*Snapshot) Resolve

func (s *Snapshot) Resolve(method, path string) MatchOutcome

func (*Snapshot) Routes

func (s *Snapshot) Routes() []Route

func (*Snapshot) ServeHTTP

func (s *Snapshot) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WalkFunc

type WalkFunc func(method, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error

Directories

Path Synopsis
internal
cmd/apimanifest command
Command apimanifest inventories a pinned go-chi/chi checkout.
Command apimanifest inventories a pinned go-chi/chi checkout.

Jump to

Keyboard shortcuts

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