nezha/pkg/mygin/error.go
2021-08-10 20:13:17 +08:00

36 lines
546 B
Go

package mygin
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/naiba/nezha/model"
)
type ErrInfo struct {
Code int
Title string
Msg string
Link string
Btn string
}
func ShowErrorPage(c *gin.Context, i ErrInfo, isPage bool) {
if isPage {
c.HTML(i.Code, "dashboard/error", CommonEnvironment(c, gin.H{
"Code": i.Code,
"Title": i.Title,
"Msg": i.Msg,
"Link": i.Link,
"Btn": i.Btn,
}))
} else {
c.JSON(http.StatusOK, model.Response{
Code: i.Code,
Message: i.Msg,
})
}
c.Abort()
}