Documentation
¶
Overview ¶
Package chi provides a Go+-authored, bounded Chi-compatible registration facade backed by immutable compiled route snapshots.
Index ¶
- Variables
- func Fold[R any](m MatchOutcome, cs MatchOutcomeCases[R]) R
- func RegisterMethod(method string)
- func URLParam(r *http.Request, key string) string
- func URLParamFromCtx(ctx context.Context, key string) string
- func Walk(r Routes, walkFn WalkFunc) error
- type ChainHandler
- type Conflict
- type ConflictKind
- type Context
- type MatchOutcome
- type MatchOutcomeCases
- type MatchedRoute
- type MethodMismatch
- type Middlewares
- type Mux
- func (m *Mux) Compile() (*Snapshot, []Conflict)
- func (m *Mux) Connect(p string, h http.HandlerFunc)
- func (m *Mux) Delete(p string, h http.HandlerFunc)
- func (m *Mux) Find(ctx *Context, method, path string) string
- func (m *Mux) Get(p string, h http.HandlerFunc)
- func (m *Mux) Group(fn func(Router)) Router
- func (m *Mux) Handle(pattern string, handler http.Handler)
- func (m *Mux) HandleFunc(pattern string, handler http.HandlerFunc)
- func (m *Mux) Head(p string, h http.HandlerFunc)
- func (m *Mux) Match(ctx *Context, method, path string) bool
- func (m *Mux) Method(method, pattern string, handler http.Handler)
- func (m *Mux) MethodFunc(method, pattern string, handler http.HandlerFunc)
- func (m *Mux) MethodNotAllowed(handler http.HandlerFunc)
- func (m *Mux) MethodNotAllowedHandler() http.HandlerFunc
- func (m *Mux) Middlewares() Middlewares
- func (m *Mux) Mount(pattern string, handler http.Handler)
- func (m *Mux) NotFound(handler http.HandlerFunc)
- func (m *Mux) NotFoundHandler() http.HandlerFunc
- func (m *Mux) Options(p string, h http.HandlerFunc)
- func (m *Mux) Patch(p string, h http.HandlerFunc)
- func (m *Mux) Post(p string, h http.HandlerFunc)
- func (m *Mux) Put(p string, h http.HandlerFunc)
- func (m *Mux) Query(p string, h http.HandlerFunc)
- func (m *Mux) Route(pattern string, fn func(Router)) Router
- func (m *Mux) Routes() []Route
- func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (m *Mux) Trace(p string, h http.HandlerFunc)
- func (m *Mux) Typed(method string, pattern stdroute.Pattern, handler stdroute.Handler)
- func (m *Mux) Use(middlewares ...func(http.Handler) http.Handler)
- func (m *Mux) UseCapability(middleware stdroute.Middleware)
- func (m *Mux) With(middlewares ...func(http.Handler) http.Handler) Router
- type Route
- type RouteInfo
- type RouteMissing
- type RouteParams
- type Router
- type Routes
- type Snapshot
- func (s *Snapshot) Find(ctx *Context, method, path string) string
- func (s *Snapshot) Match(ctx *Context, method, path string) bool
- func (s *Snapshot) Metadata() []RouteInfo
- func (s *Snapshot) Middlewares() Middlewares
- func (s *Snapshot) Resolve(method, path string) MatchOutcome
- func (s *Snapshot) Routes() []Route
- func (s *Snapshot) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type WalkFunc
Constants ¶
This section is empty.
Variables ¶
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)
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 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 (*Context) RoutePattern ¶
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 MethodMismatch ¶
type MethodMismatch struct {
Allowed []string
}
type 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 (*Mux) HandleFunc ¶
func (m *Mux) HandleFunc(pattern string, handler http.HandlerFunc)
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) NotFound ¶
func (m *Mux) NotFound(handler http.HandlerFunc)
func (*Mux) NotFoundHandler ¶
func (m *Mux) NotFoundHandler() http.HandlerFunc
func (*Mux) Typed ¶
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) UseCapability ¶
func (m *Mux) UseCapability(middleware stdroute.Middleware)
UseCapability consumes capability-indexed Go+ middleware at the ordinary-Go compatibility boundary.
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 Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
func (*Snapshot) Middlewares ¶
func (s *Snapshot) Middlewares() Middlewares
func (*Snapshot) Resolve ¶
func (s *Snapshot) Resolve(method, path string) MatchOutcome
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. |