Documentation ¶
Index ¶
- func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request, methods map[string]HandlerFunc)
- func ShowErrorsPanicHandler(w http.ResponseWriter, r *http.Request, err interface{})
- func SimplePanicHandler(w http.ResponseWriter, r *http.Request, err interface{})
- type HandlerFunc
- type PanicHandler
- type RedirectBehavior
- type TreeMux
- func (t *TreeMux) DELETE(path string, handler HandlerFunc)
- func (t *TreeMux) Dump() string
- func (t *TreeMux) GET(path string, handler HandlerFunc)
- func (t *TreeMux) HEAD(path string, handler HandlerFunc)
- func (t *TreeMux) Handle(verb, path string, handler HandlerFunc)
- func (t *TreeMux) OPTIONS(path string, handler HandlerFunc)
- func (t *TreeMux) PATCH(path string, handler HandlerFunc)
- func (t *TreeMux) POST(path string, handler HandlerFunc)
- func (t *TreeMux) PUT(path string, handler HandlerFunc)
- func (t *TreeMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MethodNotAllowedHandler ¶
func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request, methods map[string]HandlerFunc)
MethodNotAllowedHandler is the default handler for TreeMux.MethodNotAllowedHandler. It writes the status code http.StatusMethodNotAllowed, and nothing else.
func ShowErrorsPanicHandler ¶
func ShowErrorsPanicHandler(w http.ResponseWriter, r *http.Request, err interface{})
ShowErrorsPanicHandler prints a nice representation of an error to the browser. This was taken from github.com/gocraft/web, which adapted it from the Traffic project.
func SimplePanicHandler ¶
func SimplePanicHandler(w http.ResponseWriter, r *http.Request, err interface{})
SimplePanicHandler just returns error 500.
Types ¶
type HandlerFunc ¶
type PanicHandler ¶
type PanicHandler func(http.ResponseWriter, *http.Request, interface{})
type RedirectBehavior ¶
type RedirectBehavior int
RedirectBehavior sets the behavior when the router redirects the request to the canonical version of the requested URL using RedirectTrailingSlash or RedirectClean. The default behavior is to return a 301 status, redirecting the browser to the version of the URL that matches the given pattern.
On a POST request, most browsers that receive a 301 will submit a GET request to the redirected URL, meaning that any data will likely be lost. If you want to handle and avoid this behavior, you may use Redirect307, which causes most browsers to resubmit the request using the original method and request body.
Since 307 is supposed to be a temporary redirect, the new 308 status code has been proposed, which is treated the same, except it indicates correctly that the redirection is permanent. The big caveat here is that the RFC is relatively recent, and older browsers will not know what to do with it. Therefore its use is not recommended unless you really know what you're doing.
Finally, the UseHandler value will simply call the handler function for the pattern.
const ( Redirect301 RedirectBehavior = iota // Return 301 Moved Permanently Redirect307 // Return 307 HTTP/1.1 Temporary Redirect Redirect308 // Return a 308 RFC7538 Permanent Redirect UseHandler // Just call the handler function )
type TreeMux ¶
type TreeMux struct { // The default PanicHandler just returns a 500 code. PanicHandler PanicHandler // The default NotFoundHandler is http.NotFound. NotFoundHandler func(w http.ResponseWriter, r *http.Request) // MethodNotAllowedHandler is called when a pattern matches, but that // pattern does not have a handler for the requested method. The default // handler just writes the status code http.StatusMethodNotAllowed and adds // the required Allowed header. // The methods parameter contains the map of each method to the corresponding // handler function. MethodNotAllowedHandler func(w http.ResponseWriter, r *http.Request, methods map[string]HandlerFunc) // HeadCanUseGet allows the router to use the GET handler to respond to // HEAD requests if no explicit HEAD handler has been added for the // matching pattern. This is true by default. HeadCanUseGet bool // RedirectCleanPath allows the router to try clean the current request path, // if no handler is registered for it, using CleanPath from github.com/dimfeld/httppath. // This is true by default. RedirectCleanPath bool // RedirectTrailingSlash enables automatic redirection in case router doesn't find a matching route // for the current request path but a handler for the path with or without the trailing // slash exists. This is true by default. RedirectTrailingSlash bool // RemoveCatchAllTrailingSlash removes the trailing slash when a catch-all pattern // is matched, if set to true. By default, catch-all paths are never redirected. RemoveCatchAllTrailingSlash bool // RedirectBehavior sets the default redirect behavior when RedirectTrailingSlash or // RedirectCleanPath are true. The default value is Redirect301. RedirectBehavior RedirectBehavior // RedirectMethodBehavior overrides the default behavior for a particular HTTP method. // The key is the method name, and the value is the behavior to use for that method. RedirectMethodBehavior map[string]RedirectBehavior // contains filtered or unexported fields }
func (*TreeMux) DELETE ¶
func (t *TreeMux) DELETE(path string, handler HandlerFunc)
func (*TreeMux) GET ¶
func (t *TreeMux) GET(path string, handler HandlerFunc)
func (*TreeMux) HEAD ¶
func (t *TreeMux) HEAD(path string, handler HandlerFunc)
func (*TreeMux) Handle ¶
func (t *TreeMux) Handle(verb, path string, handler HandlerFunc)
func (*TreeMux) OPTIONS ¶
func (t *TreeMux) OPTIONS(path string, handler HandlerFunc)
func (*TreeMux) PATCH ¶
func (t *TreeMux) PATCH(path string, handler HandlerFunc)
func (*TreeMux) POST ¶
func (t *TreeMux) POST(path string, handler HandlerFunc)
func (*TreeMux) PUT ¶
func (t *TreeMux) PUT(path string, handler HandlerFunc)