支持view自定义返回
This commit is contained in:
1 parent
78bb246390
commit
c0ac9a6397
12 files changed
+73
-56
No files matched your search
@@ -1,6 +1,9 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -73,3 +76,19 @@ func GenerateMsgIDFromContext(c *gin.Context) string {
|
||||
msgID = cast.ToString(data)
|
||||
return msgID
|
||||
}
|
||||
|
||||
// GetOrm 获取orm连接
|
||||
func GetOrm(c *gin.Context) (*gorm.DB, error) {
|
||||
msgID := 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))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user