From c848b9a08b518e97ece05ea617d82503004a70c6 Mon Sep 17 00:00:00 2001 From: naiba Date: Tue, 10 Aug 2021 20:13:17 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20[dashboard=200.9.17]=20404=20?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- cmd/dashboard/controller/common_page.go | 1 + cmd/dashboard/controller/controller.go | 13 +++++++++++++ model/common.go | 2 +- pkg/mygin/auth.go | 2 +- pkg/mygin/error.go | 4 ++-- service/dao/dao.go | 2 +- 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b785cff..5044c37 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
LOGO designed by 熊大 .

-    +   

:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。

diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go index e675ff8..6be7dfa 100644 --- a/cmd/dashboard/controller/common_page.go +++ b/cmd/dashboard/controller/common_page.go @@ -45,6 +45,7 @@ func (p *commonPage) issueViewPassword(c *gin.Context) { } if err != nil { mygin.ShowErrorPage(c, mygin.ErrInfo{ + Code: http.StatusOK, Title: "出现错误", Msg: fmt.Sprintf("请求错误:%s", err), }, true) diff --git a/cmd/dashboard/controller/controller.go b/cmd/dashboard/controller/controller.go index 9ffda7f..5cb92fa 100644 --- a/cmd/dashboard/controller/controller.go +++ b/cmd/dashboard/controller/controller.go @@ -113,6 +113,19 @@ func ServeWeb(port uint) *http.Server { r.Static("/static", "resource/static") r.LoadHTMLGlob("resource/template/**/*") routers(r) + + page404 := func(c *gin.Context) { + mygin.ShowErrorPage(c, mygin.ErrInfo{ + Code: http.StatusNotFound, + Title: "该页面不存在", + Msg: "该页面内容可能已着陆火星", + Link: "/", + Btn: "返回首页", + }, true) + } + r.NoRoute(page404) + r.NoMethod(page404) + srv := &http.Server{ Addr: fmt.Sprintf(":%d", port), Handler: r, diff --git a/model/common.go b/model/common.go index 096dc42..05ac8a7 100644 --- a/model/common.go +++ b/model/common.go @@ -14,7 +14,7 @@ type Common struct { } type Response struct { - Code uint64 `json:"code,omitempty"` + Code int `json:"code,omitempty"` Message string `json:"message,omitempty"` Result interface{} `json:"result,omitempty"` } diff --git a/pkg/mygin/auth.go b/pkg/mygin/auth.go index 83726d9..8233a7f 100644 --- a/pkg/mygin/auth.go +++ b/pkg/mygin/auth.go @@ -22,7 +22,7 @@ type AuthorizeOption struct { func Authorize(opt AuthorizeOption) func(*gin.Context) { return func(c *gin.Context) { - var code uint64 = http.StatusForbidden + var code = http.StatusForbidden if opt.Guest { code = http.StatusBadRequest } diff --git a/pkg/mygin/error.go b/pkg/mygin/error.go index 0b0e2fd..a849622 100644 --- a/pkg/mygin/error.go +++ b/pkg/mygin/error.go @@ -9,7 +9,7 @@ import ( ) type ErrInfo struct { - Code uint64 + Code int Title string Msg string Link string @@ -18,7 +18,7 @@ type ErrInfo struct { func ShowErrorPage(c *gin.Context, i ErrInfo, isPage bool) { if isPage { - c.HTML(http.StatusOK, "dashboard/error", CommonEnvironment(c, gin.H{ + c.HTML(i.Code, "dashboard/error", CommonEnvironment(c, gin.H{ "Code": i.Code, "Title": i.Title, "Msg": i.Msg, diff --git a/service/dao/dao.go b/service/dao/dao.go index 725b102..4e8b04c 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -13,7 +13,7 @@ import ( pb "github.com/naiba/nezha/proto" ) -var Version = "v0.9.16" // !!记得修改 README 中的 badge 版本!! +var Version = "v0.9.17" // !!记得修改 README 中的 badge 版本!! var ( Conf *model.Config