Documentation
¶
Index ¶
- func GetAllParams(r *http.Request) paramsMapType
- func GetParam(r *http.Request, key string) string
- type MiddlewareType
- type Node
- type Parameters
- type Router
- func (router *Router) DELETE(path string, handle http.HandlerFunc)
- func (router *Router) DELETEAndName(path string, handle http.HandlerFunc, routeName string)
- func (router *Router) GET(path string, handle http.HandlerFunc)
- func (router *Router) GETAndName(path string, handle http.HandlerFunc, routeName string)
- func (router *Router) Generate(method string, routeName string, params map[string]string) (string, error)
- func (router *Router) Group(prefix string) *Router
- func (router *Router) Handle(method string, path string, handle http.HandlerFunc)
- func (router *Router) HandleNotFound(w http.ResponseWriter, r *http.Request, middleware []MiddlewareType)
- func (router *Router) Match(requestUrl string, path string) bool
- func (router *Router) NotFoundFunc(handler http.HandlerFunc)
- func (router *Router) PATCH(path string, handle http.HandlerFunc)
- func (router *Router) PATCHAndName(path string, handle http.HandlerFunc, routeName string)
- func (router *Router) POST(path string, handle http.HandlerFunc)
- func (router *Router) POSTAndName(path string, handle http.HandlerFunc, routeName string)
- func (router *Router) PUT(path string, handle http.HandlerFunc)
- func (router *Router) PUTAndName(path string, handle http.HandlerFunc, routeName string)
- func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (router *Router) Use(middleware ...MiddlewareType)
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAllParams ¶
GetAllParams return all route params stored in r.
Types ¶
type MiddlewareType ¶ added in v1.0.1
type MiddlewareType func(next http.HandlerFunc) http.HandlerFunc
MiddlewareType is a public type that is used for middleware
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node records any URL params, and executes an end handler.
type Parameters ¶ added in v1.1.0
type Parameters struct {
// contains filtered or unexported fields
}
Parameters records some parameters
type Router ¶
type Router struct { // PanicHandler for handling panic. PanicHandler func(w http.ResponseWriter, req *http.Request, err interface{}) // contains filtered or unexported fields }
Router is a simple HTTP route multiplexer that parses a request path, records any URL params, and executes an end handler.
func New ¶
func New() *Router
New returns a newly initialized Router object that implements the Router
func (*Router) DELETE ¶
func (router *Router) DELETE(path string, handle http.HandlerFunc)
DELETE adds the route `path` that matches a DELETE http method to execute the `handle` http.HandlerFunc.
func (*Router) DELETEAndName ¶ added in v1.1.0
func (router *Router) DELETEAndName(path string, handle http.HandlerFunc, routeName string)
DELETEAndName is short for `DELETE` and Named routeName
func (*Router) GET ¶
func (router *Router) GET(path string, handle http.HandlerFunc)
GET adds the route `path` that matches a GET http method to execute the `handle` http.HandlerFunc.
func (*Router) GETAndName ¶ added in v1.1.0
func (router *Router) GETAndName(path string, handle http.HandlerFunc, routeName string)
GETAndName is short for `GET` and Named routeName
func (*Router) Generate ¶ added in v1.1.0
func (router *Router) Generate(method string, routeName string, params map[string]string) (string, error)
Generate returns reverse routing by method, routeName and params
func (*Router) Group ¶
Group define routes groups If there is a path prefix that use `prefix`
func (*Router) Handle ¶
func (router *Router) Handle(method string, path string, handle http.HandlerFunc)
Handle registers a new request handle with the given path and method.
func (*Router) HandleNotFound ¶
func (router *Router) HandleNotFound(w http.ResponseWriter, r *http.Request, middleware []MiddlewareType)
HandleNotFound registers a handler when the request route is not found
func (*Router) Match ¶
Match check if the request match the route Pattern
func (*Router) NotFoundFunc ¶
func (router *Router) NotFoundFunc(handler http.HandlerFunc)
NotFoundFunc registers a handler when the request route is not found
func (*Router) PATCH ¶
func (router *Router) PATCH(path string, handle http.HandlerFunc)
PATCH adds the route `path` that matches a PATCH http method to execute the `handle` http.HandlerFunc.
func (*Router) PATCHAndName ¶ added in v1.1.0
func (router *Router) PATCHAndName(path string, handle http.HandlerFunc, routeName string)
PATCHAndName is short for `PATCH` and Named routeName
func (*Router) POST ¶
func (router *Router) POST(path string, handle http.HandlerFunc)
POST adds the route `path` that matches a POST http method to execute the `handle` http.HandlerFunc.
func (*Router) POSTAndName ¶ added in v1.1.0
func (router *Router) POSTAndName(path string, handle http.HandlerFunc, routeName string)
POSTAndName is short for `POST` and Named routeName
func (*Router) PUT ¶
func (router *Router) PUT(path string, handle http.HandlerFunc)
PUT adds the route `path` that matches a PUT http method to execute the `handle` http.HandlerFunc.
func (*Router) PUTAndName ¶ added in v1.1.0
func (router *Router) PUTAndName(path string, handle http.HandlerFunc, routeName string)
PUTAndName is short for `PUT` and Named routeName
func (*Router) ServeHTTP ¶
func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP makes the router implement the http.Handler interface.
func (*Router) Use ¶
func (router *Router) Use(middleware ...MiddlewareType)
Use appends a middleware handler to the middleware stack.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree records node
func NewTree ¶
func NewTree() *Tree
NewTree returns a newly initialized Tree object that implements the Tree
func (*Tree) Add ¶
func (tree *Tree) Add(pattern string, handle http.HandlerFunc, middleware ...MiddlewareType)
Add use `pattern` 、handle、middleware stack as node register to tree