Middleware is also a route handler.

Middleware will proccess the request before controller, so it cannot be the last handler in a route.

package middleware

import (



func Example() gin.HandlerFunc {
	return func(c *gin.Context) {
		t := zone.Now()

		// Set example variable
		c.Set("example", "12345")

		// before request


		// after request
		latency := zone.Since(t)
		log.Info("latency", logs.Field{"latency": latency})

		// access the status we are sending
		status := c.Writer.Status()
		log.Info("status", logs.Field{"status": status})