client.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package gd_management
  2. import (
  3. "context"
  4. "fmt"
  5. "runtime"
  6. "time"
  7. "github.com/smallnest/rpcx/client"
  8. "github.com/smallnest/rpcx/protocol"
  9. "github.com/smallnest/rpcx/share"
  10. )
  11. type GdManagementXClient struct {
  12. xcli client.XClient
  13. }
  14. func (a *GdManagementXClient) Init(etcdAddrs []string, basePath, servicePath string) {
  15. opt := client.Option{
  16. Retries: 3,
  17. RPCPath: share.DefaultRPCPath,
  18. ConnectTimeout: 10 * time.Second,
  19. SerializeType: protocol.JSON,
  20. CompressType: protocol.None,
  21. BackupLatency: 10 * time.Millisecond,
  22. }
  23. if runtime.GOOS == "windows" {
  24. d := client.NewEtcdDiscovery(fmt.Sprintf("/%s", basePath), servicePath, etcdAddrs, nil)
  25. a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt)
  26. } else {
  27. d := client.NewEtcdDiscovery(basePath, servicePath, etcdAddrs, nil)
  28. a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt)
  29. }
  30. }
  31. func (a *GdManagementXClient) InitForK8s(servicePath string, k8sServiceName string, k8sServicePort string) {
  32. opt := client.Option{
  33. Retries: 1,
  34. RPCPath: share.DefaultRPCPath,
  35. ConnectTimeout: 10 * time.Second,
  36. SerializeType: protocol.JSON,
  37. CompressType: protocol.None,
  38. BackupLatency: 10 * time.Millisecond,
  39. }
  40. sd := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%s", k8sServiceName, k8sServicePort), "")
  41. a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, sd, opt)
  42. }
  43. func (a *GdManagementXClient) ManagementGetProviderApiLimitCount(ctx context.Context, req *ManagementGetProviderApiLimitCountReq) (reply ManagementGetProviderApiLimitCountReply, err error) {
  44. err = a.xcli.Call(ctx, "ManagementGetProviderApiLimitCount", req, &reply)
  45. return
  46. }
  47. func (a *GdManagementXClient) MangementGetUserMerchantCountCode(ctx context.Context, req *MangementGetUserMerchantCountCodeReq) (reply MangementGetUserMerchantCountCodeReply, err error) {
  48. err = a.xcli.Call(ctx, "MangementGetUserMerchantCountCode", req, &reply)
  49. return
  50. }
  51. func (a *GdManagementXClient) ManagementGetProviderCountInfo(ctx context.Context, req *ManagementGetProviderCountInfoReq) (reply ManagementGetProviderCountInfoReply, err error) {
  52. err = a.xcli.Call(ctx, "ManagementGetProviderCountInfo", req, &reply)
  53. return
  54. }
  55. func (a *GdManagementXClient) ManagementGetApiShowInfo(ctx context.Context, req *ManagementGetApiShowInfoReq) (reply ManagementGetApiShowInfoReply, err error) {
  56. err = a.xcli.Call(ctx, "ManagementGetApiShowInfo", req, &reply)
  57. return
  58. }
  59. func (a *GdManagementXClient) ManagementGetMerchantApiTimeout(ctx context.Context, req *ManagementGetMerchantApiTimeoutReq) (reply ManagementGetMerchantApiTimeoutReply, err error) {
  60. err = a.xcli.Call(ctx, "ManagementGetMerchantApiTimeout", req, &reply)
  61. return
  62. }