Documentation ¶
Index ¶
- Constants
- func DefaultSkipper(*rux.Context) bool
- func DumpRoutesHandler() rux.HandlerFunc
- func GenRequestID() rux.HandlerFunc
- func HTTPBasicAuth(accounts map[string]string) rux.HandlerFunc
- func HTTPMethodOverrideHandler(h http.Handler) http.Handler
- func IgnoreFavIcon() rux.HandlerFunc
- func PanicsHandler() rux.HandlerFunc
- func RequestLogger() rux.HandlerFunc
- func Timeout(timeout time.Duration) rux.HandlerFunc
- type Skipper
Examples ¶
Constants ¶
const ( // HTTPMethodOverrideHeader is a commonly used http header to override a request method HTTPMethodOverrideHeader = "X-HTTP-Method-Override" // HTTPMethodOverrideFormKey is a commonly used HTML form key to override a request method HTTPMethodOverrideFormKey = "_method" // OriginalMethodContextKey is a commonly for record old original request method OriginalMethodContextKey contextKey = "originalMethod" )
const FavIcon = "/favicon.ico"
FavIcon uri for favicon.ico
Variables ¶
This section is empty.
Functions ¶
func DefaultSkipper ¶ added in v1.2.5
DefaultSkipper returns false which processes the middleware.
func DumpRoutesHandler ¶
func DumpRoutesHandler() rux.HandlerFunc
DumpRoutesHandler dump all registered routes info
func HTTPBasicAuth ¶ added in v1.0.2
func HTTPBasicAuth(accounts map[string]string) rux.HandlerFunc
HTTPBasicAuth for the request Usage:
r.GET("/auth", func(c *rux.Context) { c.WriteString("hello") }, HTTPBasicAuth(map[string]string{"testuser": "123"}))
func HTTPMethodOverrideHandler ¶
HTTPMethodOverrideHandler wraps and returns a http.Handler which checks for the X-HTTP-Method-Override header or the _method form key, and overrides (if valid) request.Method with its value.
It is ref from the https://github.com/gorilla/handlers
Example ¶
r := rux.New() h := HTTPMethodOverrideHandler(r) http.ListenAndServe(":8080", h) // can also: h1 := r.WrapHTTPHandlers(HTTPMethodOverrideHandler) http.ListenAndServe(":8080", h1)
Output:
func Timeout ¶ added in v1.3.0
func Timeout(timeout time.Duration) rux.HandlerFunc
Timeout is a middleware for handle logic. the method is refer from "github.com/go-chi/chi/middleware"
It's required that you select the ctx.Done() channel to check for the signal if the context has reached its deadline and return, otherwise the timeout signal will be just ignored.
ie. a route/handler may look like:
r.GET("/long", func(c *rux.Context) { ctx := c.Req.Context() processTime := time.Duration(rand.Intn(4)+1) * time.Second select { case <-ctx.Done(): return case <-time.After(processTime): // The above channel simulates some hard work. } c.WriteBytes([]byte("done")) })