mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
feat✨ :更新api写法,同步调整模版
This commit is contained in:
+25
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user