Documentation ¶
Index ¶
- Variables
- func CleanPath(p string) string
- type Handler
- type Method
- type Param
- type Params
- type Request
- type Router
- func (r *Router) DELETE(path string, h Handler)
- func (r *Router) GET(path string, h Handler)
- func (r *Router) HandleFunc(path string, h http.HandlerFunc, ms ...Method)
- func (r *Router) Handler(path string, h http.Handler, ms ...Method)
- func (r *Router) Lookup(method Method, path string) (Handler, Params, bool)
- func (r *Router) PATCH(path string, h Handler)
- func (r *Router) POST(path string, h Handler)
- func (r *Router) PUT(path string, h Handler)
- func (r *Router) Route(path string, h Handler, methods ...Method)
- func (r *Router) ServeFiles(path string, root http.FileSystem)
- func (router *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CleanPath ¶
CleanPath is the URL version of path.Clean, it returns a canonical URL path for p, eliminating . and .. elements.
The following rules are applied iteratively until no further processing can be done:
- Replace multiple slashes with a single slash.
- Eliminate each . path name element (the current directory).
- Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
- Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.
If the result of this process is an empty string, "/" is returned
Types ¶
type Method ¶
type Method string
The router is built on: https://github.com/julienschmidt/httprouter Copyright 2013 Julien Schmidt. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
type Request ¶
func NewRequest ¶
NewRequest wraps the http.Request and adds an auth.User if valid
func (*Request) QueryValues ¶
TODO This function is messy and doesn't make much sense - prefer mocks over tricks with context for testing
type Router ¶
type Router struct { RedirectTrailingSlash bool RedirectFixedPath bool // contains filtered or unexported fields }
Router is a http.Handler which can be used to dispatch requests to different handler functions via configurable routes
func (*Router) HandleFunc ¶
func (r *Router) HandleFunc(path string, h http.HandlerFunc, ms ...Method)
HandleFunc adapts the given http.HandleFunc so it can be served for every given method by the router.
func (*Router) Handler ¶
Handler adapts the given http.Handler so it can be served for every given method by the router.
func (*Router) ServeFiles ¶
func (r *Router) ServeFiles(path string, root http.FileSystem)
ServeFiles serves files from the given file system path.
func (*Router) ServeHTTP ¶
func (router *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP dispatches the request to the handler whose pattern and method matches the request. It will also get an auth.User if the session is valid, pass context to the matched handler, and generate any parameters requested by the route.