Documentation
¶
Overview ¶
Package routing provides framework-agnostic route groups, middleware, and a Router interface implemented by Gin, Fiber, and net/http+chi adapters.
Canonical parameter syntax is {id}, which adapters translate to their framework-specific syntax (:id for Gin/Fiber, {id} for chi).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TranslatePattern ¶
TranslatePattern converts a canonical v2 pattern ({id}) to the framework-specific syntax. The target format is either "gin" (":id") or "chi" ("{id}").
func ValidatePattern ¶
ValidatePattern checks that a pattern uses valid canonical syntax. Returns an error if the pattern contains malformed parameter braces.
Types ¶
type Handler ¶
type Handler func(*webFramework.RequestContext) error
Handler is a v2 route handler that receives a RequestContext and returns an error. If the handler returns a non-nil error, the error is routed through the error handler registry.
func AdaptLegacy ¶
AdaptLegacy wraps a v1 handler function (func(context.Context)) into a v2 Handler. The v1 handler is invoked with the RequestContext's LegacyContext, which is the framework-native context expected by libContext.InitContext.
This adapter does NOT expose v2 session, worker, or renderer features to the legacy handler. The legacy handler runs on the v1 lifecycle. Errors from the legacy handler are not captured (v1 handlers typically write responses directly and do not return errors).
func AdaptLegacyWithError ¶
AdaptLegacyWithError wraps a v1 handler function that returns an error. If the legacy handler returns a non-nil error, it is propagated to the v2 error handler registry.
type Middleware ¶
Middleware wraps a Handler with additional behavior. Middleware functions are composed in registration order: the first registered middleware is the outermost wrapper.
func Chain ¶
func Chain(middleware ...Middleware) Middleware
Chain composes multiple middleware into a single middleware. The first middleware in the slice is the outermost wrapper.
type RouteGroup ¶
type RouteGroup interface {
// Group creates a sub-group with the given prefix appended to the
// current group's prefix. The new group inherits the current
// group's middleware.
Group(prefix string) RouteGroup
// With returns a new group that adds the given middleware to the
// current group's middleware chain. The original group is unchanged.
With(middleware ...Middleware) RouteGroup
// Handle registers a handler for the given method and pattern.
// The pattern uses canonical syntax: {id} for path parameters.
Handle(method, pattern string, handler Handler) error
// Convenience methods for common HTTP methods.
Get(pattern string, handler Handler) error
Post(pattern string, handler Handler) error
Put(pattern string, handler Handler) error
Patch(pattern string, handler Handler) error
Delete(pattern string, handler Handler) error
Head(pattern string, handler Handler) error
}
RouteGroup represents a group of routes with a shared path prefix and middleware chain.
type Router ¶
type Router interface {
RouteGroup
// NotFound sets the handler for unmatched routes.
NotFound(handler Handler)
// MethodNotAllowed sets the handler for disallowed methods on
// matched paths.
MethodNotAllowed(handler Handler)
// Native returns the underlying framework-specific router object
// (e.g. *gin.Engine, *fiber.App, *chi.Mux). This is an escape hatch
// for framework-specific configuration.
Native() any
}
Router extends RouteGroup with not-found and method-not-allowed handlers.