Browse Source

路由打印

pull/272/head
娄文智 3 years ago
parent
commit
312eb15a83
3 changed files with 48 additions and 2 deletions
  1. +45
    -0
      conf/app.go
  2. +2
    -1
      main.go
  3. +1
    -1
      services/qm/View.service.go

+ 45
- 0
conf/app.go View File

@ -1,8 +1,11 @@
package conf
import (
"LAPP_GAAS_GFrame_BACKEND/web/supports"
"fmt"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/logger"
rcover "github.com/kataras/iris/v12/middleware/recover"
)
var ExampleFile = "http://localhost:8093/public/uploadxlsx/example.xlsx"
@ -88,3 +91,45 @@ func AppOtherParse() {
O.Secret = c.GetOther()[secret].(string)
}
// 注册中间件、定义错误处理
func PreSettring(app *iris.Application) {
app.Logger().SetLevel(AppConfig.Other.LogLevel)
customLogger := logger.New(logger.Config{
//状态显示状态代码
Status: true,
// IP显示请求的远程地址
IP: true,
//方法显示http方法
Method: true,
// Path显示请求路径
Path: true,
// Query将url查询附加到Path。
Query: true,
//Columns:true,
// 如果不为空然后它的内容来自`ctx.Values(),Get("logger_message")
//将添加到日志中。
MessageContextKeys: []string{"logger_message"},
//如果不为空然后它的内容来自`ctx.GetHeader(“User-Agent”)
MessageHeaderKeys: []string{"User-Agent"},
})
app.Use(
rcover.New(),
customLogger,
//middleware.ServeHTTP
)
// ---------------------- 定义错误处理 ------------------------
app.OnErrorCode(iris.StatusNotFound, customLogger, func(ctx iris.Context) {
supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil)
})
//app.OnErrorCode(iris.StatusForbidden, customLogger, func(ctx iris.Context) {
// ctx.JSON(utils.Error(iris.StatusForbidden, "权限不足", nil))
//})
//捕获所有http错误:
//app.OnAnyErrorCode(customLogger, func(ctx iris.Context) {
// //这应该被添加到日志中,因为`logger.Config#MessageContextKey`
// ctx.Values().Set("logger_message", "a dynamic message passed to the logs")
// ctx.JSON(utils.Error(500, "服务器内部错误", nil))
//})
}

+ 2
- 1
main.go View File

@ -108,7 +108,8 @@ func imain() {
conf.AppOtherParse()
app := iris.New()
//注册中间件
//conf.PreSettring(app)
//注册路由
routes.Hub(app)
app.RegisterView(iris.HTML("./web/public", ".html"))


+ 1
- 1
services/qm/View.service.go View File

@ -183,7 +183,7 @@ type ViewService interface {
*
* @Function Parameters : 当前访问人员信息
*
* @Function Parameters : Article标识
* @Function Parameters : 序列订单OrderId
*
* @Return Value : 与指定Article关联的视图
*


Loading…
Cancel
Save