first commit

This commit is contained in:
Yangtao
2025-11-18 17:48:20 +08:00
commit 6e56cab848
196 changed files with 65809 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package middleware
import (
"github.com/gin-gonic/gin"
"net/http"
"runtime/debug"
)
func Recover(c *gin.Context) {
defer func() {
if r := recover(); r != nil {
debug.PrintStack()
c.JSON(http.StatusOK, gin.H{
"code": 500,
"message": "系统异常",
"detailError": errorToString(r),
"data": nil,
})
c.Abort()
}
}()
c.Next()
}
func errorToString(r interface{}) string {
switch v := r.(type) {
case error:
return v.Error()
default:
return r.(string)
}
}