router

package module
v2.12.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2015 License: MIT Imports: 12 Imported by: 0

README

router

A router that integrates with go-on/wrap

Build Status Coverage Status Project status GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRouteId

func GetRouteId(req *http.Request) (id string)

func GetRouteParam

func GetRouteParam(req *http.Request, key string) string

func GetURLParam

func GetURLParam(u *url.URL, key string) (res string)

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

type ErrInvalidMountPath struct {
	Path   string
	Reason string
}

func (ErrInvalidMountPath) Error

func (e ErrInvalidMountPath) Error() string

type ErrMethodNotDefinedForRoute

type ErrMethodNotDefinedForRoute struct {
	method.Method
	Route *route.Route
}

func (*ErrMethodNotDefinedForRoute) Error

type ErrMissingHandler

type ErrMissingHandler struct {
	Route *route.Route
	// contains filtered or unexported fields
}

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

type FileServer struct {
	Dir string

	http.Handler
	// contains filtered or unexported fields
}

func NewFileServer

func NewFileServer(fs http.Handler, dir string, route *route.Route) *FileServer

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

func (*FileServer) SetHandler

func (fs *FileServer) SetHandler()

TODO: rename if to mount

func (*FileServer) URL

func (fs *FileServer) URL(relativePath string) (string, error)

type Muxer

type Muxer interface {
	Handle(path string, handler http.Handler)
}

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) DELETE

func (r *Router) DELETE(path string, handler http.Handler) *route.Route

func (*Router) DELETEFunc

func (r *Router) DELETEFunc(path string, handler http.HandlerFunc) *route.Route

func (*Router) Dispatch

func (r *Router) Dispatch(rq *http.Request) http.Handler

Dispatch returns the corresponding http.Handler for the request If no handler could be found, nil is returned

func (*Router) EachRoute

func (r *Router) EachRoute(fn func(mountPoint string, route *route.Route))

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) GET

func (r *Router) GET(path string, handler http.Handler) *route.Route

func (*Router) GETFunc

func (r *Router) GETFunc(path string, handler http.HandlerFunc) *route.Route

func (*Router) Handle

func (r *Router) Handle(path string, handler http.Handler)

Handle registers a handler for all routes. Use it to mount sub routers

func (*Router) HandleMethod

func (r *Router) HandleMethod(path string, handler http.Handler, m method.Method) *route.Route

func (*Router) HandleMethods

func (r *Router) HandleMethods(path string, handler http.Handler, method1 method.Method, furtherMethods ...method.Method) *route.Route

func (*Router) HandleRoute

func (r *Router) HandleRoute(rt *route.Route, handler http.Handler)

func (*Router) HandleRouteDELETE

func (r *Router) HandleRouteDELETE(rt *route.Route, handler http.Handler)

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 (r *Router) HandleRouteGET(rt *route.Route, handler http.Handler)

func (*Router) HandleRouteGETFunc

func (r *Router) HandleRouteGETFunc(rt *route.Route, handler http.HandlerFunc)

func (*Router) HandleRouteMethods

func (r *Router) HandleRouteMethods(rt *route.Route, handler http.Handler, method1 method.Method, furtherMethods ...method.Method)

func (*Router) HandleRouteMethodsFunc

func (r *Router) HandleRouteMethodsFunc(rt *route.Route, handler http.HandlerFunc, method1 method.Method, furtherMethods ...method.Method)

func (*Router) HandleRouteOPTIONS

func (r *Router) HandleRouteOPTIONS(rt *route.Route, handler http.Handler)

func (*Router) HandleRouteOPTIONSFunc

func (r *Router) HandleRouteOPTIONSFunc(rt *route.Route, handler http.HandlerFunc)

func (*Router) HandleRoutePATCH

func (r *Router) HandleRoutePATCH(rt *route.Route, handler http.Handler)

func (*Router) HandleRoutePATCHFunc

func (r *Router) HandleRoutePATCHFunc(rt *route.Route, handler http.HandlerFunc)

func (*Router) HandleRoutePOST

func (r *Router) HandleRoutePOST(rt *route.Route, handler http.Handler)

func (*Router) HandleRoutePOSTFunc

func (r *Router) HandleRoutePOSTFunc(rt *route.Route, handler http.HandlerFunc)

func (*Router) HandleRoutePUT

func (r *Router) HandleRoutePUT(rt *route.Route, handler http.Handler)

func (*Router) HandleRoutePUTFunc

func (r *Router) HandleRoutePUTFunc(rt *route.Route, handler http.HandlerFunc)

func (*Router) IsMounted

func (r *Router) IsMounted() bool

func (*Router) Mount

func (r *Router) Mount(path string, parent Muxer)

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) MountPath

func (ø *Router) MountPath() string

func (*Router) MountWrapped

func (r *Router) MountWrapped(path string, parent Muxer, wrappers ...wrap.Wrapper)

MountWrapped mounts the router to the parent at path, wrapped by the given wrappers

func (*Router) PATCH

func (r *Router) PATCH(path string, handler http.Handler) *route.Route

func (*Router) PATCHFunc

func (r *Router) PATCHFunc(path string, handler http.HandlerFunc) *route.Route

func (*Router) POST

func (r *Router) POST(path string, handler http.Handler) *route.Route

func (*Router) POSTFunc

func (r *Router) POSTFunc(path string, handler http.HandlerFunc) *route.Route

func (*Router) PUT

func (r *Router) PUT(path string, handler http.Handler) *route.Route

func (*Router) PUTFunc

func (r *Router) PUTFunc(path string, handler http.HandlerFunc) *route.Route

func (*Router) RequestRoute

func (ø *Router) RequestRoute(rq *http.Request) (rt *route.Route)

func (*Router) Route

func (r *Router) Route(definitionPath string) *route.Route

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

func (ø *Router) ServingHandler() http.Handler

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

func (*Router) Wrap

func (ø *Router) Wrap(h http.Handler) http.Handler

Wrap wraps the given inner handler with all wrappers of the router and its parents Wrap is part of the route/MountedRouter interface and should only be used internally, even if being exported

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
t

Jump to

Keyboard shortcuts

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