mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
增加service实现
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user