feat✨优化配置信息

This commit is contained in:
wenjianzhang committed 2021-05-08 16:50:51 +08:00
1 parent f56839926e
commit 6222765e20
5 files changed
+46 -30

No files matched your search

+22 -3
View File
@@ -2,10 +2,10 @@ package apis
import (
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/logger"
"github.com/go-admin-team/go-admin-core/sdk/pkg/response"
@@ -19,11 +19,12 @@ type Api struct {
func (e Api) SetContext(c *gin.Context) {
e.Context = c
e.Logger = api.GetRequestLogger(c)
}
// GetLogger 获取上下文提供的日志
func (e Api) GetLogger() *logger.Logger {
e.Logger = api.GetRequestLogger(e.Context)
return e.Logger
}
@@ -33,6 +34,24 @@ func (e Api) Bind(d interface{}, bindings ...binding.Binding) error {
switch bindings[i] {
case binding.JSON:
err = e.Context.ShouldBindWith(d, binding.JSON)
case binding.XML:
err = e.Context.ShouldBindWith(d, binding.XML)
case binding.Form:
err = e.Context.ShouldBindWith(d, binding.Form)
case binding.Query:
err = e.Context.ShouldBindWith(d, binding.Query)
case binding.FormPost:
err = e.Context.ShouldBindWith(d, binding.FormPost)
case binding.FormMultipart:
err = e.Context.ShouldBindWith(d, binding.FormMultipart)
case binding.ProtoBuf:
err = e.Context.ShouldBindWith(d, binding.ProtoBuf)
case binding.MsgPack:
err = e.Context.ShouldBindWith(d, binding.MsgPack)
case binding.YAML:
err = e.Context.ShouldBindWith(d, binding.YAML)
case binding.Header:
err = e.Context.ShouldBindWith(d, binding.Header)
default:
err = e.Context.ShouldBindUri(d)
}
@@ -71,4 +90,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)
}
}