Documentation ¶
Index ¶
- Variables
- func Connect(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- func Delete(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- func Get(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- func Head(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- func IfHttpMethod(needMethod string, rw http.ResponseWriter, r *http.Request, ...)
- func Options(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- func Patch(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- func Post(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- func Put(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- func Trace(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
- type HttpHandler
- type HttpHandlerStruct
- type HttpNotAllowHandler
- type IfHttpMethodHandler
Constants ¶
This section is empty.
Variables ¶
var DefaultHTTPHeaders [][]string
Define default Http Response headers Example:
[][]string{ {"x-content-type-options", "nosniff"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, } // define default headers
Functions ¶
func Connect ¶
func Connect(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is CONNECT
func Delete ¶
func Delete(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is DELETE
func Get ¶
func Get(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is GET
func Head ¶
func Head(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is HEAD
func IfHttpMethod ¶
func IfHttpMethod(needMethod string, rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if needMethod is equal r.Method
func Options ¶
func Options(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is OPTIONS
func Patch ¶
func Patch(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is PATCH
func Post ¶
func Post(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is POST
func Put ¶
func Put(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is PUT
func Trace ¶
func Trace(rw http.ResponseWriter, r *http.Request, handler IfHttpMethodHandler)
Helper func to check r.Method and call handler only if r.Method is TRACE
Types ¶
type HttpHandler ¶
type HttpHandler func(http.ResponseWriter, *http.Request)
It is main HttpHandler, which is called only, when Http method is allowed
func NewFileServerHandler ¶ added in v1.2.0
func NewFileServerHandler(fsPath string) HttpHandler
Create http Handler for serving files in fsPath directory. If file not found return 404 status and serve error404.html if exist
func (HttpHandler) ServeHTTP ¶
func (fn HttpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
Compressing Http response by using gzipResponseWriter (only if Accept-Encoding request header is set and contains gzip value) and also add DefaultHttpHeaders to Http response
type HttpHandlerStruct ¶
type HttpHandlerStruct struct { NotAllowHandler HttpNotAllowHandler Handler HttpHandler AllowedMethods []string AllowedOrigins []string }
The main struct, where You can define Handler (it is main HttpHandler, which is called only, when Http method is allowed), NotAllowHandler (it is HttpHandler, which is called only if Http method is not allowed) and AllowedMethods ([]string array, which contains allowed HTTP method names) You must call func Build to build HttpHandler.
In version v1.1 added AllowedOrigins field (optional): use if you want to check Origin header
func (HttpHandlerStruct) Build ¶
func (builder HttpHandlerStruct) Build() HttpHandler
Build HttpHandler, which can by used in http.Handle (but not in http.HandleFunc, because only http.Handle call ServeHTTP)
type HttpNotAllowHandler ¶
type HttpNotAllowHandler func(http.ResponseWriter, *http.Request)
It is HttpHandler, which is called only if Http method is not allowed
type IfHttpMethodHandler ¶
type IfHttpMethodHandler func(http.ResponseWriter, *http.Request)
Http handler for use in IfHttpMethod func