Documentation ¶
Index ¶
- func GetRouteId(req *http.Request) (id string)
- func GetRouteParam(req *http.Request, key string) string
- func GetURLParam(u *url.URL, key string) (res string)
- func SetOPTIONSHandler(r *routeHandler)
- type ErrDoubleMounted
- type ErrDoubleRegistration
- type ErrHandlerAlreadyDefined
- type ErrInvalidMountPath
- type ErrMethodNotDefinedForRoute
- type ErrMissingHandler
- type ErrNotMounted
- type ErrRouterNotAllowed
- type ErrUnknownMethod
- type FileServer
- type Muxer
- type Router
- func (r *Router) DELETE(path string, handler http.Handler) *route.Route
- func (r *Router) DELETEFunc(path string, handler http.HandlerFunc) *route.Route
- func (r *Router) Dispatch(rq *http.Request) http.Handler
- func (r *Router) EachRoute(fn func(mountPoint string, route *route.Route))
- func (r *Router) FileServer(path, dir string) *FileServer
- func (r *Router) GET(path string, handler http.Handler) *route.Route
- func (r *Router) GETFunc(path string, handler http.HandlerFunc) *route.Route
- func (r *Router) Handle(path string, handler http.Handler)
- func (r *Router) HandleMethod(path string, handler http.Handler, m method.Method) *route.Route
- func (r *Router) HandleMethods(path string, handler http.Handler, method1 method.Method, ...) *route.Route
- func (r *Router) HandleRoute(rt *route.Route, handler http.Handler)
- func (r *Router) HandleRouteDELETE(rt *route.Route, handler http.Handler)
- func (r *Router) HandleRouteDELETEFunc(rt *route.Route, handler http.HandlerFunc)
- func (r *Router) HandleRouteFunc(rt *route.Route, handler http.HandlerFunc)
- func (r *Router) HandleRouteGET(rt *route.Route, handler http.Handler)
- func (r *Router) HandleRouteGETFunc(rt *route.Route, handler http.HandlerFunc)
- func (r *Router) HandleRouteMethods(rt *route.Route, handler http.Handler, method1 method.Method, ...)
- func (r *Router) HandleRouteMethodsFunc(rt *route.Route, handler http.HandlerFunc, method1 method.Method, ...)
- func (r *Router) HandleRouteOPTIONS(rt *route.Route, handler http.Handler)
- func (r *Router) HandleRouteOPTIONSFunc(rt *route.Route, handler http.HandlerFunc)
- func (r *Router) HandleRoutePATCH(rt *route.Route, handler http.Handler)
- func (r *Router) HandleRoutePATCHFunc(rt *route.Route, handler http.HandlerFunc)
- func (r *Router) HandleRoutePOST(rt *route.Route, handler http.Handler)
- func (r *Router) HandleRoutePOSTFunc(rt *route.Route, handler http.HandlerFunc)
- func (r *Router) HandleRoutePUT(rt *route.Route, handler http.Handler)
- func (r *Router) HandleRoutePUTFunc(rt *route.Route, handler http.HandlerFunc)
- func (r *Router) IsMounted() bool
- func (r *Router) Mount(path string, parent Muxer)
- func (ø *Router) MountPath() string
- func (r *Router) MountWrapped(path string, parent Muxer, wrappers ...wrap.Wrapper)
- func (r *Router) PATCH(path string, handler http.Handler) *route.Route
- func (r *Router) PATCHFunc(path string, handler http.HandlerFunc) *route.Route
- func (r *Router) POST(path string, handler http.Handler) *route.Route
- func (r *Router) POSTFunc(path string, handler http.HandlerFunc) *route.Route
- func (r *Router) PUT(path string, handler http.Handler) *route.Route
- func (r *Router) PUTFunc(path string, handler http.HandlerFunc) *route.Route
- func (ø *Router) RequestRoute(rq *http.Request) (rt *route.Route)
- func (r *Router) Route(definitionPath string) *route.Route
- func (r *Router) ServeHTTP(w http.ResponseWriter, rq *http.Request)
- func (ø *Router) ServingHandler() http.Handler
- func (ø *Router) Wrap(h http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRouteId ¶
func GetURLParam ¶
since req.URL.Path has / unescaped so that originally escaped / are indistinguishable from escaped ones, we are save here, i.e. / is already handled as path splitted and no key or value has / in it also it is save to use req.URL.Fragment since that will never be transmitted by the request
func SetOPTIONSHandler ¶
func SetOPTIONSHandler(r *routeHandler)
Types ¶
type ErrDoubleMounted ¶
type ErrDoubleMounted struct {
Path string
}
func (ErrDoubleMounted) Error ¶
func (e ErrDoubleMounted) Error() string
type ErrDoubleRegistration ¶
type ErrDoubleRegistration struct {
DefinitionPath string
}
func (ErrDoubleRegistration) Error ¶
func (e ErrDoubleRegistration) Error() string
type ErrHandlerAlreadyDefined ¶
type ErrHandlerAlreadyDefined struct {
method.Method
}
func (ErrHandlerAlreadyDefined) Error ¶
func (e ErrHandlerAlreadyDefined) Error() string
type ErrInvalidMountPath ¶
func (ErrInvalidMountPath) Error ¶
func (e ErrInvalidMountPath) Error() string
type ErrMethodNotDefinedForRoute ¶
func (*ErrMethodNotDefinedForRoute) Error ¶
func (e *ErrMethodNotDefinedForRoute) Error() string
type ErrMissingHandler ¶
func (*ErrMissingHandler) Error ¶
func (e *ErrMissingHandler) Error() string
type ErrNotMounted ¶
type ErrNotMounted struct{}
func (ErrNotMounted) Error ¶
func (e ErrNotMounted) Error() string
type ErrRouterNotAllowed ¶
type ErrRouterNotAllowed struct{}
func (ErrRouterNotAllowed) Error ¶
func (e ErrRouterNotAllowed) Error() string
type ErrUnknownMethod ¶
type ErrUnknownMethod struct {
method.Method
}
func (ErrUnknownMethod) Error ¶
func (e ErrUnknownMethod) Error() string
type FileServer ¶
func NewFileServer ¶
func (*FileServer) Exists ¶
func (fs *FileServer) Exists(relativePath string) bool
Exists returns if the given file exist beneath the base Dir of the FileServer
func (*FileServer) MustURL ¶
func (fs *FileServer) MustURL(relativePath string) string
type Router ¶
type Router struct { // NotFound is called, if a http.Handler could not be found. // If it is set to nil, the status 405 is set NotFound http.Handler // contains filtered or unexported fields }
Router is a mountable router routing paths to routes.
Concurrently adding and serving routes is not supported. Routes must be defined none concurrently and before serving
func New ¶
func New(wrapper ...wrap.Wrapper) (r *Router)
New creates a new router with optional wrappers
func NewETagged ¶
func NewETagged(wrappers ...wrap.Wrapper) (r *Router)
func (*Router) DELETEFunc ¶
func (*Router) Dispatch ¶
Dispatch returns the corresponding http.Handler for the request If no handler could be found, nil is returned
func (*Router) FileServer ¶
func (r *Router) FileServer(path, dir string) *FileServer
FileServer serves the files from the given directory under the given path
func (*Router) HandleMethod ¶
func (*Router) HandleMethods ¶
func (*Router) HandleRouteDELETE ¶
func (*Router) HandleRouteDELETEFunc ¶
func (r *Router) HandleRouteDELETEFunc(rt *route.Route, handler http.HandlerFunc)
func (*Router) HandleRouteFunc ¶
func (r *Router) HandleRouteFunc(rt *route.Route, handler http.HandlerFunc)
func (*Router) HandleRouteGET ¶
func (*Router) HandleRouteGETFunc ¶
func (r *Router) HandleRouteGETFunc(rt *route.Route, handler http.HandlerFunc)
func (*Router) HandleRouteMethods ¶
func (*Router) HandleRouteMethodsFunc ¶
func (r *Router) HandleRouteMethodsFunc(rt *route.Route, handler http.HandlerFunc, method1 method.Method, furtherMethods ...method.Method)
func (*Router) HandleRouteOPTIONS ¶
func (*Router) HandleRouteOPTIONSFunc ¶
func (r *Router) HandleRouteOPTIONSFunc(rt *route.Route, handler http.HandlerFunc)
func (*Router) HandleRoutePATCH ¶
func (*Router) HandleRoutePATCHFunc ¶
func (r *Router) HandleRoutePATCHFunc(rt *route.Route, handler http.HandlerFunc)
func (*Router) HandleRoutePOST ¶
func (*Router) HandleRoutePOSTFunc ¶
func (r *Router) HandleRoutePOSTFunc(rt *route.Route, handler http.HandlerFunc)
func (*Router) HandleRoutePUT ¶
func (*Router) HandleRoutePUTFunc ¶
func (r *Router) HandleRoutePUTFunc(rt *route.Route, handler http.HandlerFunc)
func (*Router) Mount ¶
Mount mounts the router to the parent at path. The parent might be nil in which case only the mount path is registered inside the router
func (*Router) MountWrapped ¶
MountWrapped mounts the router to the parent at path, wrapped by the given wrappers
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, rq *http.Request)
ServeHTTP serves the request via the http.Handler that is defined in the route to which the url points. If no route is found or no handler for the requested method is found, the NotFound handler serves the request. If there is no NotFound handler, the status code 405 (Method not allowed) is sent.
ServeHTTP should be used as part of a composition. There are things that should only be done once per request, such as protocol checking and path normalization. These should be done by the toplevel Handler, see the Serve() http.HandlerFunc
func (*Router) ServingHandler ¶
Serve serves the request on the top level. It handles method override and path cleaning and then serves via the corresponding http.Handler of the route or passes it to a given wrapper
Serve will selfmount the router under / if it is not already mounted
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
example
|
|
internal
|
|
Package route provides slim representation of routes that is used by go-on/router.Router and may be used by client side libraries such as gopherjs.
|
Package route provides slim representation of routes that is used by go-on/router.Router and may be used by client side libraries such as gopherjs. |
routehtml
Package routehtml provides shortcuts to deal with route and go-on/lib/html
|
Package routehtml provides shortcuts to deal with route and go-on/lib/html |
tea
|
|