init commit

This commit is contained in:
wizardchen
2025-08-05 15:08:07 +08:00
commit 56eb2bce33
282 changed files with 49077 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package middleware
import (
"fmt"
"log"
"runtime/debug"
"github.com/gin-gonic/gin"
)
// Recovery is a middleware that recovers from panics
func Recovery() gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
// Get request ID
requestID, _ := c.Get("RequestID")
// Print stacktrace
stacktrace := debug.Stack()
// Log error
log.Printf("[PANIC] %s | %v | %s", requestID, err, stacktrace)
// 返回500错误
c.AbortWithStatusJSON(500, gin.H{
"error": "Internal Server Error",
"message": fmt.Sprintf("%v", err),
})
}
}()
c.Next()
}
}