Documentation ¶
Index ¶
- Variables
- func AddCurrentRoute(r *http.Request, route RouteInterface) *http.Request
- func AddRouteParameters(r *http.Request, params map[string]string) *http.Request
- func GetQueries(r *http.Request) *middleware.Queries
- func GetRouteParameters(r *http.Request) map[string]string
- func NewBadMethodError() error
- func NewBadPathError(text string) error
- func NewMethodValidator() methodValidator
- func NewPathValidator() pathValidator
- func NewTree(nodeConstructor func() *Node) func() RouteTreeInterface
- func NodeOfType(seg string) nodeType
- type BadMethodError
- type BadPathError
- type Handlers
- type Node
- type Route
- func (r *Route) AddHandler(method string, handler http.Handler) RouteInterface
- func (r *Route) AddHandlerFunc(method string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
- func (r *Route) AddHandlers(handlers Handlers) RouteInterface
- func (r *Route) GetHandler(method string) http.Handler
- func (r *Route) GetHandlers() Handlers
- func (r *Route) GetPattern() string
- func (r *Route) HasHandler(method string) bool
- func (r *Route) SetPattern(pattern string) RouteInterface
- type RouteInterface
- type RouteTreeInterface
- type Router
- func (r *Router) Delete(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
- func (r *Router) Get(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
- func (r *Router) Handle(method string, pattern string, ...) RouteInterface
- func (r *Router) HandleFunc(method string, pattern string, handler http.Handler) RouteInterface
- func (r *Router) Head(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
- func (r *Router) Options(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
- func (r *Router) Patch(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
- func (r *Router) Path(pattern string, callback func(route RouteInterface)) RouteInterface
- func (r *Router) Post(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
- func (r *Router) Put(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
- func (r *Router) RegisterRoute(route RouteInterface)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(middlewares ...middleware.Middleware)
- func (r *Router) UseRoute(constructor func() RouteInterface)
- func (r *Router) UseTree(constructor func() RouteTreeInterface)
- func (r *Router) ValidateRoute(route RouteInterface)
- type Tree
- type Validator
Constants ¶
This section is empty.
Variables ¶
var Methods = newMethods()
var Validatoren = []Validator{ NewPathValidator(), NewMethodValidator(), }
Functions ¶
func AddCurrentRoute ¶
func AddCurrentRoute(r *http.Request, route RouteInterface) *http.Request
AddCurrentRoute adds a route instance to the current request context
func AddRouteParameters ¶
AddCurrentRoute adds parameters of path to the current request context
func GetQueries ¶
func GetQueries(r *http.Request) *middleware.Queries
GetQueries returns the query variables for the current request.
func GetRouteParameters ¶
GetRouteParameter returns the parameters of route for a given request This only works when called inside the handler of the matched route because the matched route is stored in the request context which is cleared after the handler returns
func NewBadMethodError ¶
func NewBadMethodError() error
NewBadMethodError returns an error that formats as the given text.
func NewBadPathError ¶
NewBadPathError returns an error that formats as the given text.
func NewMethodValidator ¶
func NewMethodValidator() methodValidator
func NewPathValidator ¶
func NewPathValidator() pathValidator
func NewTree ¶
func NewTree(nodeConstructor func() *Node) func() RouteTreeInterface
NewTree returns an empty Radix Tree
func NodeOfType ¶
func NodeOfType(seg string) nodeType
Types ¶
type BadMethodError ¶
type BadMethodError struct{}
BadMethodError creates error for bad method
func (*BadMethodError) Error ¶
func (bme *BadMethodError) Error() string
type BadPathError ¶
type BadPathError struct {
// contains filtered or unexported fields
}
BadPathError creates error for bad path
func (*BadPathError) Error ¶
func (bme *BadPathError) Error() string
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func (*Route) AddHandler ¶
func (r *Route) AddHandler(method string, handler http.Handler) RouteInterface
func (*Route) AddHandlerFunc ¶
func (r *Route) AddHandlerFunc(method string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
func (*Route) AddHandlers ¶
func (r *Route) AddHandlers(handlers Handlers) RouteInterface
func (*Route) GetHandlers ¶
func (*Route) GetPattern ¶
func (*Route) HasHandler ¶
func (*Route) SetPattern ¶
func (r *Route) SetPattern(pattern string) RouteInterface
type RouteInterface ¶
type RouteInterface interface { AddHandler(string, http.Handler) RouteInterface AddHandlerFunc(string, func(http.ResponseWriter, *http.Request)) RouteInterface SetPattern(string) RouteInterface GetPattern() string GetHandler(string) http.Handler HasHandler(string) bool GetHandlers() Handlers AddHandlers(Handlers) RouteInterface }
func GetCurrentRoute ¶
func GetCurrentRoute(r *http.Request) RouteInterface
CurrentRoute returns the matched route for the current request. This only works when called inside the handler of the matched route because the matched route is stored in the request context which is cleared after the handler returns
func NewRoute ¶
func NewRoute() RouteInterface
type RouteTreeInterface ¶
type RouteTreeInterface interface { UseNode(func() *Node) Insert(RouteInterface) RouteInterface Find(*Node, string) (RouteInterface, map[string]string, error) GetRoot() *Node }
RouteTreeInterface if like you to implement your own tree version, feel free to do it
type Router ¶
type Router struct { // Configurable Handler to be used when no route matches. NotFoundHandler http.Handler // This defines the flag for new routes. StrictSlash bool // This defines the flag for new routes. SkipClean bool // This defines a flag for all routes. UseEncodedPath bool // This defines a flag for all routes. CaseSensitiveURL bool // contains filtered or unexported fields }
Router registers routes to be matched and dispatches a handler.
It implements the http.Handler interface, so it can be registered to serve requests:
var router = trixie.NewRouter() func main() { http.Handle("/", router) }
This will send all incoming requests to the router.
func (*Router) Delete ¶
func (r *Router) Delete(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
Delete registers a new delete route for the URL path
func (*Router) Get ¶
func (r *Router) Get(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
Get registers a new get route for the URL path
func (*Router) Handle ¶
func (r *Router) Handle(method string, pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
Handle registers a new route with a matcher for the URL path.
func (*Router) HandleFunc ¶
HandleFunc registers a new route with a matcher for the URL path.
func (*Router) Head ¶
func (r *Router) Head(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
Head registers a new head route for the URL path
func (*Router) Options ¶
func (r *Router) Options(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
Options registers a new options route for the URL path
func (*Router) Patch ¶
func (r *Router) Patch(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
Patch registers a new patch route for the URL path
func (*Router) Path ¶
func (r *Router) Path(pattern string, callback func(route RouteInterface)) RouteInterface
func (*Router) Post ¶
func (r *Router) Post(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
Post registers a new post route for the URL path
func (*Router) Put ¶
func (r *Router) Put(pattern string, handler func(http.ResponseWriter, *http.Request)) RouteInterface
Put registers a new put route for the URL path
func (*Router) RegisterRoute ¶
func (r *Router) RegisterRoute(route RouteInterface)
RegisterRoute registers and validates the given route
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP dispatches the handler registered in the matched route.
When there is a match, the route variables can be retrieved calling trixie.GetRouteParameters(req)
and the route queries can be retrieved calling middleware.GetQueries(req).Get("content-type") or middleware.GetQueries(req).GetAll()
func (*Router) Use ¶
func (r *Router) Use(middlewares ...middleware.Middleware)
Use appends a middleware handler to the mux middleware stack.
func (*Router) UseRoute ¶
func (r *Router) UseRoute(constructor func() RouteInterface)
UseRoute that you can use different route versions See RouteInterface for more details (route.go)
func (*Router) UseTree ¶
func (r *Router) UseTree(constructor func() RouteTreeInterface)
UseTree that you can use different tree versions See TreeInterface for more details (tree.go)
func (*Router) ValidateRoute ¶
func (r *Router) ValidateRoute(route RouteInterface)
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
func (*Tree) Insert ¶
func (t *Tree) Insert(newRoute RouteInterface) RouteInterface
Insert is used to add a new entry or update an existing entry.
type Validator ¶
type Validator interface {
Validate(RouteInterface) error
}
Validator validates the incomming value against a valid value/s