1 Star 0 Fork 0

PengHengBen / devcloud-mini

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
impl.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
PengHengBen 提交于 2024-02-18 17:10 . 补充trace
package impl
import (
"gitee.com/penghengben/devcloud-mini/mcenter/apps/role"
"gitee.com/penghengben/devcloud-mini/mcenter/conf"
"github.com/infraboard/mcube/ioc"
"go.mongodb.org/mongo-driver/mongo"
"google.golang.org/grpc"
)
func init() {
ioc.RegistryController(&impl{})
}
// 显示的约束对象接口
var _ role.Service = (*impl)(nil)
type impl struct {
// 继承GRPC 服务方法模板
role.UnimplementedRpcServer
// ioc
ioc.IocObjectImpl
// mongo
col *mongo.Collection
}
func (i *impl) Init() error {
// 补充Mongo依赖
db, err := conf.C().MongoDB.GetDB()
if err != nil {
panic(err)
}
// 缺少事物补充,但是问题不大,如果删除后注册失败,再重新注册还是可以正常使用
// sess, err := db.Client().StartSession()
// sess.StartTransaction()
// sess.Client().Database("dd").Collection("xx").InsertMany(ctx,xxx)
// sess.CommitTransaction()
// sess.EndSession()
i.col = db.Collection(role.AppName)
return nil
}
func (i *impl) Name() string {
return role.AppName
}
func (i *impl) Registry(server *grpc.Server) {
role.RegisterRpcServer(server, i)
}
Go
1
https://gitee.com/penghengben/devcloud-mini.git
git@gitee.com:penghengben/devcloud-mini.git
penghengben
devcloud-mini
devcloud-mini
52595909206d

搜索帮助