支持view自定义返回
This commit is contained in:
1 parent
78bb246390
commit
c0ac9a6397
12 files changed
+73
-56
No files matched your search
+1
-20
@@ -1,9 +1,6 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
@@ -14,21 +11,5 @@ type Api struct {
|
||||
}
|
||||
|
||||
func (e *Api) GetOrm(c *gin.Context) (*gorm.DB, error) {
|
||||
return GetOrm(c)
|
||||
}
|
||||
|
||||
// GetOrm 获取orm连接
|
||||
func GetOrm(c *gin.Context) (*gorm.DB, error) {
|
||||
msgID := tools.GenerateMsgIDFromContext(c)
|
||||
idb, exist := c.Get("db")
|
||||
if !exist {
|
||||
return nil, errors.New(fmt.Sprintf("msgID[%s], db connect not exist", msgID))
|
||||
}
|
||||
switch idb.(type) {
|
||||
case *gorm.DB:
|
||||
//新增操作
|
||||
return idb.(*gorm.DB), nil
|
||||
default:
|
||||
return nil, errors.New(fmt.Sprintf("msgID[%s], db connect not exist", msgID))
|
||||
}
|
||||
return tools.GetOrm(c)
|
||||
}
|
||||
Reference in new issue
Block a user