feat: 迁移plant
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package svc
|
||||
|
||||
import (
|
||||
@@ -9,7 +6,10 @@ import (
|
||||
"sundynix-micro-go/app/plant/rpc/plantservice"
|
||||
"sundynix-micro-go/app/system/rpc/systemservice"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
@@ -17,13 +17,20 @@ type ServiceContext struct {
|
||||
PlantRpc plantservice.PlantService
|
||||
UserRpc systemservice.SystemService
|
||||
FileRpc fileservice.FileService
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
db, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{})
|
||||
if err != nil {
|
||||
logx.Errorf("连接数据库失败: %v", err)
|
||||
}
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
PlantRpc: plantservice.NewPlantService(zrpc.MustNewClient(c.PlantRpc)),
|
||||
UserRpc: systemservice.NewSystemService(zrpc.MustNewClient(c.UserRpc)),
|
||||
FileRpc: fileservice.NewFileService(zrpc.MustNewClient(c.FileRpc)),
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user