stdrouter

package
v0.0.0-...-4d6f19f Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const MethodAny = "ANY"

Variables

View Source
var HandlerKeyUserValue = "stdprouter.handler_id"
View Source
var ParamsKey = paramsKey{}

Functions

This section is empty.

Types

type Handler

type Handler interface {
	ServeHTTP(http.ResponseWriter, *http.Request, Params)
}

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request, Params)

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(rw http.ResponseWriter, r *http.Request, p Params)

type HandlerID

type HandlerID int

type Param

type Param struct {
	Key   string
	Value string
}

type Params

type Params []Param

func ParamsFromContext

func ParamsFromContext(ctx context.Context) Params

ParamsFromContext pulls the URL parameters from a request context, or returns nil if none are present.

func (Params) Get

func (ps Params) Get(name string) string

func (*Params) Set

func (ps *Params) Set(name, value string)

type Router

type Router struct {
	PageNotFoundHandler     http.HandlerFunc
	MethodNotAllowedHandler http.HandlerFunc
	GlobalHandler           Handler

	Trees []radix.Tree
	// contains filtered or unexported fields
}

func New

func New() *Router

func (*Router) Add

func (r *Router) Add(method, path string, handlerID HandlerID) error

func (*Router) AddHandler

func (r *Router) AddHandler(handler Handler) HandlerID

func (*Router) AddStdHandler

func (r *Router) AddStdHandler(handler http.Handler) HandlerID

func (*Router) FindHandler

func (r *Router) FindHandler(method, path string) (Handler, error)

func (*Router) GetHandler

func (r *Router) GetHandler(hID HandlerID) (Handler, error)

func (*Router) RegisterHandler

func (r *Router) RegisterHandler(method, path string, handler Handler) error

func (*Router) Remove

func (r *Router) Remove(method, path string) error

func (*Router) RemoveHandler

func (r *Router) RemoveHandler(hID HandlerID)

func (*Router) ServeHTTP

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

Jump to

Keyboard shortcuts

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