Documentation ¶
Overview ¶
Package web is a minimal web middleware toolkit build upon build upon the Go 1.7 immutable context(https://golang.org/pkg/context).
app := web.New() app.Use(assert.Middleware()) app.Use(web.Mount("/assets", serve.Dir("public"))) app.Use(logger.Middleware()) app.Use(timeout.Timeout("15s")) app.Use(sessions.Middleware( cookieName, sessions.NewCookieStore([]byte("secret")), )) app.Use(routes.Public()) if err := app.Run("0.0.0.0:3000"); err != nil { log.Fatal(err) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface { // Add a middleware to the middleware stack. Use(Middleware) // UseHandler can be used to use a http.Handler as a middleware. UseHandler(http.Handler) // UseFunc can be used to use a http.HandlerFunc as a middleware. UseFunc(http.HandlerFunc) // Execute the middleware stack using the provided context. Execute(http.ResponseWriter, *http.Request, http.HandlerFunc) // Serve the middleware stack through HTTP. ServeHTTP(http.ResponseWriter, *http.Request) // Run a http server on the given address. Run(addr string) error // Run a https server on the given address using the provided certificate. RunTLS(addr, certFile, keyFile string) error }
The App is used to register middlewares and serve them through HTTP.
type Middleware ¶
type Middleware func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
A middleware.
func Combine ¶
func Combine(mw ...Middleware) Middleware
Combine can be used to combine multiple middlewares into one stack.
func Func ¶
func Func(fn http.HandlerFunc) Middleware
UseHandler wraps a http.HandlerFunc into a Middleware.
func Handler ¶
func Handler(handler http.Handler) Middleware
UseHandler wraps a http.Handler into a Middleware.
func Mount ¶
func Mount(path string, mw Middleware) Middleware
Mount can be used to mount a middleware to the specified path / path-prefix. If the the path matches, the matched part ist trimmed and the middleware is called. Otherwise, the middleware is skipped.
Click to show internal directories.
Click to hide internal directories.