代码优化

This commit is contained in:
meilin.huang
2021-04-21 10:22:09 +08:00
parent ec1001d88b
commit d5fc1b6f52
14 changed files with 64 additions and 226 deletions

View File

@@ -4,16 +4,11 @@ import (
"mayfly-go/base/ginx"
"mayfly-go/base/model"
"net/http"
"time"
"github.com/gin-gonic/gin"
)
// // 获取数据函数
// type getDataFunc func(*ReqCtx) interface{}
// // 操作函数,无返回数据
// type operationFunc func(*ReqCtx)
// 处理函数
type HandlerFunc func(*ReqCtx)
@@ -28,6 +23,7 @@ type ReqCtx struct {
ReqParam interface{} // 请求参数,主要用于记录日志
ResData interface{} // 响应结果
err interface{} // 请求错误
timed int64 // 执行时间
}
func (rc *ReqCtx) Handle(handler HandlerFunc) {
@@ -56,7 +52,9 @@ func (rc *ReqCtx) Handle(handler HandlerFunc) {
panic(err)
}
begin := time.Now()
handler(rc)
rc.timed = time.Now().Sub(begin).Milliseconds()
ginx.SuccessRes(ginCtx, rc.ResData)
}