Documentation ¶
Overview ¶
Package httputil provides an easy way to chain handlers and a server with timeouts and graceful shutdown.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InternalServerError ¶
InternalServerError returns an handler which writes status code 500 and logs the error string.
func ListenAndServe ¶
ListenAndServe listens on the TCP network address addr and starts an HTTP server with timeouts. It returns a shutdown function for the server.
Example:
stop := make(chan os.Signal, 1) signal.Notify(stop, os.Interrupt, syscall.SIGTERM) shutdown := httputil.ListenAndServe(":8080", router, stop) defer shutdown() <-stop
func Origin ¶
Origin returns the scheme plus host (including port, if available). The scheme is https, except when the host looks like localhost or a Tor hidden service.
If you use nginx as a reverse proxy, make sure you have set "proxy_set_header Host $host;" besides proxy_pass in your configuration.
Types ¶
type HandlerFunc ¶
A HandlerFunc can return the next handler or nil, which provides easy chaining:
mux.Handle("/", httputil.HandlerFunc(func(w http.ResponseWriter, r *http.Request) http.Handler { // do something, then return next handler or nil }))
You can return http.NotFoundHandler and http.RedirectHandler for not found errors and redirects.
func (HandlerFunc) ServeHTTP ¶
func (f HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)