routing

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package routing provides a small route registry backed by net/http ServeMux matching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

MiddlewareFunc wraps an HTTP handler with cross-cutting behavior.

type Route

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

Route is a registered path or prefix route.

func (*Route) GetHandler

func (rt *Route) GetHandler() http.Handler

GetHandler returns the route handler.

func (*Route) GetMethods

func (rt *Route) GetMethods() ([]string, error)

GetMethods returns the configured HTTP methods.

func (*Route) GetName

func (rt *Route) GetName() string

GetName returns the route name.

func (*Route) GetPathTemplate

func (rt *Route) GetPathTemplate() (string, error)

GetPathTemplate returns the route path template.

func (*Route) Handler

func (rt *Route) Handler(handler http.Handler) *Route

Handler assigns the HTTP handler for the route.

func (*Route) HandlerFunc

func (rt *Route) HandlerFunc(handler func(http.ResponseWriter, *http.Request)) *Route

HandlerFunc assigns the HTTP handler function for the route.

func (*Route) Methods

func (rt *Route) Methods(methods ...string) *Route

Methods restricts the route to the supplied HTTP methods.

func (*Route) Name

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

Name assigns a lookup name to the route.

type Router

type Router struct {
	NotFoundHandler         http.Handler
	MethodNotAllowedHandler http.Handler
	// contains filtered or unexported fields
}

Router stores named routes and dispatches requests through a net/http ServeMux.

func NewRouter

func NewRouter() *Router

NewRouter creates an empty Router.

func (*Router) CloneExcluding

func (r *Router) CloneExcluding(names map[string]bool) *Router

CloneExcluding returns a router clone without the named routes in names.

func (*Router) Get

func (r *Router) Get(name string) *Route

Get returns a named route, or nil when no route is registered under name.

func (*Router) Handle

func (r *Router) Handle(pattern string, handler http.Handler)

Handle registers handler for an exact path pattern.

func (*Router) HandleFunc

func (r *Router) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers handler for an exact path pattern.

func (*Router) Path

func (r *Router) Path(path string) *Route

Path registers an exact route path and returns it for further configuration.

func (*Router) PathPrefix

func (r *Router) PathPrefix(prefix string) *Route

PathPrefix registers a prefix route and returns it for further configuration.

func (*Router) ServeHTTP

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

func (*Router) Use

func (r *Router) Use(middleware ...MiddlewareFunc)

Use appends global middleware applied to all registered route handlers.

Jump to

Keyboard shortcuts

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