增加service实现

This commit is contained in:
linwenxiang committed 2020-09-15 13:59:01 +08:00
1 parent 3d5a2ea9f7
commit bb07d90407
5 files changed
+182 -3

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
package apis
import (
"errors"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
type Api struct {
}
// GetOrm 获取orm连接
func (e *Api) GetOrm(c *gin.Context) (*gorm.DB, error) {
idb, exist := c.Get("db")
if !exist {
return nil, errors.New("db connect not exist")
}
switch idb.(type) {
case *gorm.DB:
//新增操作
return idb.(*gorm.DB), nil
default:
return nil, errors.New("db connect not exist")
}
}
+8
View File
@@ -0,0 +1,8 @@
package service
import "gorm.io/gorm"
type Service struct {
Orm *gorm.DB
Msg string
}