|
|
@ -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))
|
|
|
|
//})
|
|
|
|
} |