mux

package
v0.0.0-...-730ab69 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 3 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, pattern).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

func Params

func Params(r *http.Request) map[string]string

Params gets URL params from the request context.

Types

type Mux

type Mux struct {
	NotFound http.HandlerFunc
	// 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, pattern string) *route

Handle sets a route with a custom HTTP method.

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