nezha/pkg/mygin/error.go
2021-01-16 00:45:49 +08:00

36 lines
556 B
Go

package mygin
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/naiba/nezha/model"
)
type ErrInfo struct {
Code uint64
Title string
Msg string
Link string
Btn string
}
func ShowErrorPage(c *gin.Context, i ErrInfo, isPage bool) {
if isPage {
c.HTML(http.StatusOK, "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()
}