mux

package
v0.0.0-...-d4b955d Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package mux implements a request router and dispatcher for matching incoming requests to their respective handler.

Inspired by:

https://github.com/nmerouze/stack

Usage

router := mux.NewRouter()
router.Use(globalMiddleware1, globalMiddleware2, ...)
router.Handle(method, path).Use(middleware1, middleware2, ...).Then(handler)
http.ListenAndServe(addr, router)

See cmd/server/main.go for example.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mux

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

func NewRouter

func NewRouter() *Mux

func (*Mux) DELETE

func (m *Mux) DELETE(p string) *route

DELETE sets a route with the DELETE HTTP method.

func (*Mux) GET

func (m *Mux) GET(p string) *route

GET sets a route with the GET HTTP method.

func (*Mux) Handle

func (m *Mux) Handle(method string, path string) *route

Handle sets a route with a custom HTTP method.

func (*Mux) NewSubRouter

func (m *Mux) NewSubRouter(prefix string) *Mux

NewSubRouter creates a new sub-router with the given prefix. The returned Mux shares the same underlying ServeMux as the parent, so all handlers are registered on the same ServeMux. The prefix is prepended to all routes registered via HandleFunc on the sub-router.

Example:

router := NewMux()
apiRouter := router.NewSubRouter("/api/v0")
apiRouter.HandleFunc("/hello", HelloHandler)

func (*Mux) PATCH

func (m *Mux) PATCH(p string) *route

PATCH sets a route with the PATCH HTTP method.

func (*Mux) POST

func (m *Mux) POST(p string) *route

POST sets a route with the POST HTTP method.

func (*Mux) PUT

func (m *Mux) PUT(p string) *route

PUT sets a route with the PUT HTTP method.

func (*Mux) ServeHTTP

func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for the router.

func (*Mux) Use

func (m *Mux) Use(middlewares ...middleware) *Mux

Use adds global middlewares to the router.

Jump to

Keyboard shortcuts

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