1 Star 0 Fork 0

谈子文/keyauth-tz

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
impl.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
谈子文 提交于 2023-10-27 04:06 . 中间件支持鉴权
package impl
import (
"gitee.com/talk-about-articles/keyauth-tz/apps/policy"
"gitee.com/talk-about-articles/keyauth-tz/apps/role"
"gitee.com/talk-about-articles/keyauth-tz/conf"
"github.com/infraboard/mcube/app"
"github.com/infraboard/mcube/logger"
"github.com/infraboard/mcube/logger/zap"
"go.mongodb.org/mongo-driver/mongo"
"google.golang.org/grpc"
)
var (
// Service 服务实例
svr = &service{}
)
type service struct {
col *mongo.Collection
log logger.Logger
policy.UnimplementedRPCServer
role role.Service
}
func (s *service) Config() error {
// 依赖Mongodb的DB对象
db, err := conf.C().Mongo.GetDB()
if err != nil {
return err
}
// 获取一个Collection对象,通过collection对象完成数据库操作
s.col = db.Collection(s.Name())
s.role = app.GetInternalApp(role.AppName).(role.Service)
s.log = zap.L().Named(s.Name())
return nil
}
func (s *service) Name() string {
return policy.AppName
}
func (s *service) Registry(server *grpc.Server) {
policy.RegisterRPCServer(server, svr)
}
func init() {
app.RegistryInternalApp(svr)
app.RegistryGrpcApp(svr)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/talk-about-articles/keyauth-tz.git
git@gitee.com:talk-about-articles/keyauth-tz.git
talk-about-articles
keyauth-tz
keyauth-tz
v1.0.25

搜索帮助