feat :更新api写法,同步调整模版

This commit is contained in:
wenjianzhang
2021-05-07 17:56:15 +08:00
parent 13ff9d9e63
commit 009866ee31
7 changed files with 62 additions and 55 deletions
+25 -2
View File
@@ -1,6 +1,7 @@
package apis
import (
"github.com/gin-gonic/gin/binding"
"net/http"
"github.com/gin-gonic/gin"
@@ -13,11 +14,33 @@ import (
type Api struct {
Context *gin.Context
Logger *logger.Logger
}
func (e Api) SetContext(c *gin.Context) {
e.Context = c
e.Logger = api.GetRequestLogger(c)
}
// GetLogger 获取上下文提供的日志
func (e Api) GetLogger() *logger.Logger {
return api.GetRequestLogger(e.Context)
return e.Logger
}
func (e Api) Bind(d interface{}, bindings ...binding.Binding) error {
var err error
for i := range bindings {
switch bindings[i] {
case binding.JSON:
err = e.Context.ShouldBindWith(d, binding.JSON)
default:
err = e.Context.ShouldBindUri(d)
}
if err != nil {
return err
}
}
return nil
}
// GetOrm 获取Orm DB
@@ -48,4 +71,4 @@ func (e Api) PageOK(result interface{}, count int, pageIndex int, pageSize int,
// Custom 兼容函数
func (e Api) Custom(data gin.H) {
response.Custum(e.Context, data)
}
}