Middleware

Overview

Go-Mojito allows you to add middleware. Middlewares are exactly the same as regular handlers, except that they have an additional argument to call the next handler in chain, which is required.

  • System Component
  • Custom Arguments
  • Not replaceable
  • Dependency Injection

This is a core part of the system, and works the same across all router implementations. This also means that this part cannot be swapped out easily.

Quick Start

  1. Create a middleware func without any parameters

    func myMiddleware() {}
  2. Add mojito.Context, mojito.Logger and func() error arguments to the handler.

    func myMiddleware(ctx mojito.Context, logger mojito.Logger, next func() error) {}
  3. Register the middleware on the router using the Go-Mojito shortcut. This will enable the middleware for all routes on the router.

    func main() {
        mojito.WithMiddleware(myMiddleware)
    }

FAQ

No frequently asked questions yet!