22 lines
418 B
Go
22 lines
418 B
Go
|
|
package middleware
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
"github.com/sirupsen/logrus"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Recovery 恢复中间件
|
||
|
|
func Recovery() gin.HandlerFunc {
|
||
|
|
return gin.CustomRecovery(func(c *gin.Context, recovered interface{}) {
|
||
|
|
logrus.Errorf("Panic recovered: %v", recovered)
|
||
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||
|
|
"code": 500,
|
||
|
|
"message": "服务器内部错误",
|
||
|
|
})
|
||
|
|
c.Abort()
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|