You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
353 B
Go
23 lines
353 B
Go
package middleware
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
// Handler 异常处理
|
|
func Handler(c *gin.Context) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
log.Printf("panic: internal error: ")
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": "服务器内部异常",
|
|
})
|
|
c.Abort()
|
|
}
|
|
}()
|
|
|
|
c.Next()
|
|
}
|