Przeglądaj źródła

fix:404页面

Roc 1 rok temu
rodzic
commit
5f2fac7c11
2 zmienionych plików z 25 dodań i 0 usunięć
  1. 21 0
      controllers/error.go
  2. 4 0
      main.go

+ 21 - 0
controllers/error.go

@@ -0,0 +1,21 @@
+package controllers
+
+import "eta/eta_mobile/models"
+
+// ErrorController
+// @Description: 该控制器处理页面错误请求
+type ErrorController struct {
+	BaseCommonController
+}
+
+func (c *ErrorController) Error404() {
+	c.Data["content"] = "很抱歉您访问的地址或者方法不存在"
+	//c.TplName = "error/404.html"
+
+	br := new(models.BaseResponse).Init()
+
+	br.Msg = "您访问的资源不存在"
+	br.Ret = 404
+	c.Data["json"] = br
+	c.ServeJSON()
+}

+ 4 - 0
main.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"eta/eta_mobile/controllers"
 	"eta/eta_mobile/services/alarm_msg"
 	"fmt"
 	"runtime"
@@ -20,6 +21,9 @@ func main() {
 		web.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
 	}
 
+	// 异常处理
+	web.ErrorController(&controllers.ErrorController{})
+
 	web.BConfig.RecoverFunc = Recover
 	web.Run()
 }