routing

package
v0.0.0-...-eadd4a4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package routing provides the core interfaces and components for HTTP routing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PathParam

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

PathParam retrieves a named path parameter from the request context.

Types

type HandleResult

type HandleResult int

HandleResult indicates how a handler responded to a request.

const (
	// NotMatched means this handler did not match at all; the Router continues to the next.
	NotMatched HandleResult = iota
	// PathMatched means the path matched but the HTTP method did not; the Router should return 405.
	PathMatched HandleResult = iota
	// Handled means the request was fully processed; the Router stops immediately.
	Handled HandleResult = iota
)

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request)

HandlerFunc is a function adapter that satisfies the HttpHandler interface.

func ChainMiddlewares

func ChainMiddlewares(f HandlerFunc, middlewares []MiddlewareFunc) HandlerFunc

ChainMiddlewares wraps f with the given middlewares, outermost first.

func (HandlerFunc) Handle

Handle calls the function itself and returns Handled.

type HttpHandler

type HttpHandler interface {
	Handle(w http.ResponseWriter, r *http.Request) HandleResult
}

HttpHandler is the interface implemented by all routing components in the framework.

type MethodHandler

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

MethodHandler forwards a request to the wrapped handler only when the HTTP method matches.

func NewMethodHandler

func NewMethodHandler(method string, wrapped HttpHandler) *MethodHandler

NewMethodHandler creates a MethodHandler that wraps the given handler.

func (*MethodHandler) Handle

Handle implements HttpHandler. Returns PathMatched when the method does not match, or delegates to the wrapped handler when it does.

type MiddlewareFunc

type MiddlewareFunc func(next HandlerFunc) HandlerFunc

MiddlewareFunc wraps a HandlerFunc with additional behaviour (Decorator pattern). Middlewares are applied left-to-right: the first one in the list runs first.

type PathHandler

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

PathHandler forwards a request to the wrapped handler only when the URL path matches the pattern. Patterns support {param} syntax, e.g. /api/users/{id}.

func NewPathHandler

func NewPathHandler(pattern string, wrapped HttpHandler) *PathHandler

NewPathHandler creates a PathHandler that wraps the given handler.

func (*PathHandler) Handle

Handle implements HttpHandler. Returns NotMatched when the path does not match. On match, extracts path parameters into the request context and delegates to the wrapped handler.

Jump to

Keyboard shortcuts

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