1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- // package call gd_auth_check micro service function
- package gd_auth_check
- import (
- "context"
- "fmt"
- "gd_vehicle/apis"
- "time"
- "github.com/smallnest/rpcx/client"
- "github.com/smallnest/rpcx/protocol"
- "github.com/smallnest/rpcx/share"
- )
- type GdAuthCheckXClient struct {
- xcli client.XClient
- }
- func (a *GdAuthCheckXClient) Init(etcdAddrs []string, basePath, servicePath string) {
- opt := client.Option{
- Retries: 3,
- RPCPath: share.DefaultRPCPath,
- ConnectTimeout: 10 * time.Second,
- SerializeType: protocol.JSON,
- CompressType: protocol.None,
- BackupLatency: 10 * time.Millisecond,
- }
- d := client.NewEtcdDiscovery(basePath, servicePath, etcdAddrs, nil)
- a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt)
- }
- // k8s模式下,服务发现方式需要改为点对点,使用k8s自身的Service进行服务发现,Service名称格式必须是abc-xyz的方式,不能使用"_"
- func (a *GdAuthCheckXClient) InitForK8s(servicePath string, k8sServiceName string, k8sServicePort string) {
- opt := client.Option{
- Retries: 1,
- RPCPath: share.DefaultRPCPath,
- ConnectTimeout: 10 * time.Second,
- SerializeType: protocol.JSON,
- CompressType: protocol.None,
- BackupLatency: 10 * time.Millisecond,
- }
- sd := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%s", k8sServiceName, k8sServicePort), "")
- a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, sd, opt)
- }
- func (a *GdAuthCheckXClient) ManagementCheckProviderApi(ctx context.Context, req *apis.ManagementCheckProviderApiReq) (reply apis.ManagementCheckProviderApiReply, err error) {
- err = a.xcli.Call(ctx, "ManagementCheckProviderApi", req, &reply)
- return
- }
|