代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。