1 Star 0 Fork 0

lollipop-xyz/g7-keyauth

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
xy 提交于 2022-11-09 14:30 . add endpoint
package rpc
import (
"fmt"
"gitee.com/lollipop-xyz/g7-keyauth/apps/endpoint"
"gitee.com/lollipop-xyz/g7-keyauth/apps/token"
"github.com/infraboard/mcube/logger"
"github.com/infraboard/mcube/logger/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"github.com/infraboard/mcenter/client/rpc"
"github.com/infraboard/mcenter/client/rpc/auth"
"github.com/infraboard/mcenter/client/rpc/resolver"
)
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()
// resolver 进行解析的时候 需要mcenter客户端实例已经初始化
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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lollipop-xyz/g7-keyauth.git
git@gitee.com:lollipop-xyz/g7-keyauth.git
lollipop-xyz
g7-keyauth
g7-keyauth
v0.0.4

搜索帮助