Help us shape the future of Go! Take the 2026 Go Developer Survey

routing

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package routing provides a high-performance segment-tree HTTP router.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group is a route group with a shared prefix and middleware stack.

func (*Group) Any

func (g *Group) Any(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) []*Route

Any registers a route for all common HTTP methods.

func (*Group) Delete

func (g *Group) Delete(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

Delete registers a DELETE route on this group.

func (*Group) Get

func (g *Group) Get(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

Get registers a GET route on this group.

func (*Group) Group

func (g *Group) Group(prefix string, fn func(*Group))

Group creates a nested sub-group under this group's prefix.

func (*Group) Head

func (g *Group) Head(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

Head registers a HEAD route on this group.

func (*Group) Options

func (g *Group) Options(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

Options registers an OPTIONS route on this group.

func (*Group) Patch

func (g *Group) Patch(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

Patch registers a PATCH route on this group.

func (*Group) Post

func (g *Group) Post(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

Post registers a POST route on this group.

func (*Group) Put

func (g *Group) Put(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

Put registers a PUT route on this group.

func (*Group) Use

func (g *Group) Use(mw ...onihttp.MiddlewareFunc) *Group

Use appends middleware to this group. Returns the group for chaining.

type Route

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

Route is a handle to a registered route, used for post-registration configuration (naming, route-level middleware) and introspection.

func (*Route) GetMethod

func (r *Route) GetMethod() string

GetMethod returns the HTTP method.

func (*Route) GetName

func (r *Route) GetName() string

GetName returns the route name.

func (*Route) GetPath

func (r *Route) GetPath() string

GetPath returns the URL pattern.

func (*Route) Middleware

func (r *Route) Middleware(mw ...onihttp.MiddlewareFunc) *Route

Middleware appends route-level middleware (runs after global middleware).

func (*Route) Name

func (r *Route) Name(name string) *Route

Name sets a symbolic name for the route (used by URL generation via r.URL("name",...)).

type Router

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

Router is the OniWorks HTTP router. It matches incoming requests against a per-method segment tree and dispatches them through a precomposed middleware chain. Route matching is O(path depth), independent of the number of routes.

func New

func New() *Router

New creates a new Router with sensible defaults.

func (*Router) Any

func (r *Router) Any(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) []*Route

func (*Router) Delete

func (r *Router) Delete(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

func (*Router) Get

func (r *Router) Get(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

func (*Router) Group

func (r *Router) Group(prefix string, fn func(*Group), mw ...onihttp.MiddlewareFunc)

Group creates a route group with a shared prefix and optional middleware.

func (*Router) Head

func (r *Router) Head(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

func (*Router) NotFound

func (r *Router) NotFound(h onihttp.HandlerFunc)

NotFound sets a custom handler for unmatched routes.

func (*Router) OnError

func (r *Router) OnError(h func(*onihttp.Context, error))

OnError sets a global error handler invoked when a handler returns error.

func (*Router) Options

func (r *Router) Options(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

func (*Router) Patch

func (r *Router) Patch(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

func (*Router) Post

func (r *Router) Post(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

func (*Router) Put

func (r *Router) Put(path string, handler onihttp.HandlerFunc, mw ...onihttp.MiddlewareFunc) *Route

func (*Router) Routes

func (r *Router) Routes() []*Route

Routes returns a snapshot of all registered routes (for `oni route:list`).

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler so Router can be passed directly to http.Server.

func (*Router) URL

func (r *Router) URL(name string, params ...string) (string, error)

URL generates a URL for a named route, substituting params.

r.URL("user.show", "id", "42") → "/users/42"

func (*Router) Use

func (r *Router) Use(mw ...onihttp.MiddlewareFunc)

Use appends global middleware that runs before every route handler.

Jump to

Keyboard shortcuts

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