21 lines
325 B
Go
21 lines
325 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// Recovery is a middleware that recovers from the panic
|
|
func Recovery() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
c.JSON(http.StatusInternalServerError, err)
|
|
}
|
|
}()
|
|
|
|
c.Next()
|
|
}
|
|
}
|