Documentation ¶
Index ¶
- Variables
- func GetParam(r *http.Request, key string) string
- type Context
- type HandlerFunc
- type InputContext
- type MiddlewareType
- type Node
- type Parameters
- type ParamsMapType
- type Router
- func (r *Router) Generate(method string, routeName string, params map[string]string) (string, error)
- func (r *Router) Group(prefix string) *Router
- func (r *Router) Handle(method string, path string, handle HandlerFunc)
- func (r *Router) Match(requestURL string, path string) bool
- func (r *Router) NotFoundFunc(handler http.HandlerFunc)
- func (r *Router) Serve(inputContext InputContext) bool
- func (r *Router) Use(middleware ...MiddlewareType)
- type Tree
Constants ¶
This section is empty.
Variables ¶
var ( // ErrGenerateParameters is returned when generating a route with wrong parameters. ErrGenerateParameters = errors.New("params contains wrong parameters") // ErrNotFoundRoute is returned when generating a route that can not find route in tree. ErrNotFoundRoute = errors.New("cannot find route in tree") // ErrNotFoundMethod is returned when generating a route that can not find method in tree. ErrNotFoundMethod = errors.New("cannot find method in tree") // ErrPatternGrammar is returned when generating a route that pattern grammar error. ErrPatternGrammar = errors.New("pattern grammar error") )
Functions ¶
Types ¶
type Context ¶
type Context interface { ContextInput() InputContext parameters.Parameters }
Context of router
type InputContext ¶
InputContext of router
type MiddlewareType ¶
type MiddlewareType func(next HandlerFunc) 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 ¶
type Parameters struct {
// contains filtered or unexported fields
}
Parameters records some parameters
type ParamsMapType ¶
ParamsMapType is a private type that is used to store route params
func GetAllParams ¶
func GetAllParams(r *http.Request) ParamsMapType
GetAllParams returns all route params stored in http.Request.
type Router ¶
type Router struct { // PanicHandler for handling panic. PanicHandler func(ctx Context, 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) Generate ¶
func (r *Router) Generate(method string, routeName string, params map[string]string) (string, error)
Generate returns reverse routing by method, routeName and params
func (*Router) Handle ¶
func (r *Router) Handle(method string, path string, handle HandlerFunc)
Handle registers a new request handler with the given path and method.
func (*Router) NotFoundFunc ¶
func (r *Router) NotFoundFunc(handler http.HandlerFunc)
NotFoundFunc registers a handler when the request route is not found
func (*Router) Serve ¶
func (r *Router) Serve(inputContext InputContext) bool
Serve makes the router implement the router.Context interface.
func (*Router) Use ¶
func (r *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 (t *Tree) Add(pattern string, handle HandlerFunc, middleware ...MiddlewareType)
Add use `pattern` 、handle、middleware stack as node register to tree