func RecoveryMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		defer func() {
			if rval := recover(); rval != nil {
				debug.PrintStack()
				err, ok := rval.(error)
				if !ok {
					err = errors.Errorf("panic: %s", rval)
				}
				c.AbortWithError(http.StatusInternalServerError, err).SetType(gin.ErrorTypePrivate)
			}
		}()
		c.Next()
	}
}
Recover with error
package utils
import (
	"database/sql"
	"encoding/json"
	"fmt"
	"net/http"
	"runtime/debug"
	"time"
	log "github.com/Sirupsen/logrus"
	"github.com/pkg/errors"
	"gopkg.in/gin-gonic/gin.v1"
	"gopkg.in/go-playground/validator.v8"
)
func DataStoresMiddleware(mbdDB *sql.DB, esManager, logger, cm interface{}  , tc interface{}, cms interface{}, variables interface{}) gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Set("MDB_DB", mbdDB)
		c.Set("ES_MANAGER", esManager)
		c.Set("LOGGER", logger)
		c.Set("CACHE", cm)
		c.Set("VARIABLES", variables)
		c.Set("TOKENS_CACHE", tc)
		c.Set("CMS", cms)
		c.Next()
	}
}
func LoggerMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		start := time.Now()
		path := c.Request.URL.RequestURI()  
		c.Next()
		log.WithFields(log.Fields{
			"status":     c.Writer.Status(),
			"method":     c.Request.Method,
			"path":       path,
			"latency":    time.Now().Sub(start),
			"ip":         c.ClientIP(),
			"user-agent": c.Request.UserAgent(),
		}).Info()
	}
}