Create a Middleware

Middleware is a function that receives a Handle and returns a Handle. Let’s take ServerHeader as an example, it writes Server header and then invokes the next middleware or handler.

func ServerHeader(srv string) clevergo.MiddlewareFunc {
    return func(next clevergo.Handle) clevergo.Handle {
        return func(c *clevergo.Context) error {
            // writes server header.
            c.Response.Header().Set("Server", srv)
            // invokes the next middleware or handler.
            return next(c)

Global Middleware

    clevergo.Recovery(true), // built-in recovery middleware.

Route Group Middleware

See Route Group.

Route Middleware

See Route Middleware.

Third-party Middleware

WrapHH is an adapter that converts func(http.Handler) http.Handler to a middleware, you can use most of the third-party middleware in CleverGo without pain.

    // https://github.com/nytimes/gziphandler
comments powered by Disqus