1 Star 0 Fork 0

huyouba1/keyauth-g7

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
client.go 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
huyouba1 提交于 2024-02-29 14:17 . 添加角色校验
package rpc
import (
"fmt"
"gitee.com/huyouba1/keyauth-g7/apps/endpoint"
"gitee.com/huyouba1/keyauth-g7/apps/policy"
"gitee.com/huyouba1/keyauth-g7/apps/role"
"gitee.com/huyouba1/keyauth-g7/apps/token"
"github.com/infraboard/mcenter/client/rpc"
"github.com/infraboard/mcenter/client/rpc/auth"
"github.com/infraboard/mcenter/client/rpc/resolver"
"github.com/infraboard/mcube/logger"
"github.com/infraboard/mcube/logger/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
var (
client *ClientSet
)
// SetGlobal todo
func SetGlobal(cli *ClientSet) {
client = cli
}
// C Global
func C() *ClientSet {
return client
}
// NewClient todo
func NewClient(conf *rpc.Config) (*ClientSet, error) {
zap.DevelopmentSetup()
log := zap.L()
conn, err := grpc.Dial(
// 127.0.0.1:18010 GRPC server端的地址
// 基于服务发现 Dial to "passthrough:// dns://keyauth.org "mcenter://keyauth",
fmt.Sprintf("%s://%s", resolver.Scheme, "keyauth"),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithPerRPCCredentials(auth.NewAuthentication(conf.ClientID, conf.ClientSecret)),
grpc.WithBlock(),
)
if err != nil {
return nil, err
}
return &ClientSet{
conn: conn,
log: log,
}, nil
}
// Client 客户端
type ClientSet struct {
conn *grpc.ClientConn
log logger.Logger
}
// Token服务的SDK
func (c *ClientSet) Token() token.ServiceClient {
return token.NewServiceClient(c.conn)
}
// Endpoint服务的SDK
func (c *ClientSet) Endpoint() endpoint.RPCClient {
return endpoint.NewRPCClient(c.conn)
}
// Role服务的SDK
func (c *ClientSet) Role() role.RPCClient {
return role.NewRPCClient(c.conn)
}
// Policy服务的SDK
func (c *ClientSet) Policy() policy.RPCClient {
return policy.NewRPCClient(c.conn)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huyouba1/keyauth-g7.git
git@gitee.com:huyouba1/keyauth-g7.git
huyouba1
keyauth-g7
keyauth-g7
v0.0.6

搜索帮助