client.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package gd_auth_check
  2. import (
  3. "context"
  4. "fmt"
  5. "gd_gateway/apis"
  6. "runtime"
  7. "time"
  8. "github.com/smallnest/rpcx/client"
  9. "github.com/smallnest/rpcx/protocol"
  10. "github.com/smallnest/rpcx/share"
  11. )
  12. type GdAuthCheckXClient struct {
  13. xcli client.XClient
  14. }
  15. func (a *GdAuthCheckXClient) Init(etcdAddrs []string, basePath, servicePath string) {
  16. opt := client.Option{
  17. Retries: 3,
  18. RPCPath: share.DefaultRPCPath,
  19. ConnectTimeout: 10 * time.Second,
  20. SerializeType: protocol.JSON,
  21. CompressType: protocol.None,
  22. BackupLatency: 10 * time.Millisecond,
  23. }
  24. if runtime.GOOS == "windows" {
  25. d := client.NewEtcdDiscovery(fmt.Sprintf("/%s", basePath), servicePath, etcdAddrs, nil)
  26. a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt)
  27. } else {
  28. d := client.NewEtcdDiscovery(basePath, servicePath, etcdAddrs, nil)
  29. a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, d, opt)
  30. }
  31. }
  32. func (a *GdAuthCheckXClient) InitForK8s(servicePath string, k8sServiceName string, k8sServicePort string) {
  33. opt := client.Option{
  34. Retries: 1,
  35. RPCPath: share.DefaultRPCPath,
  36. ConnectTimeout: 10 * time.Second,
  37. SerializeType: protocol.JSON,
  38. CompressType: protocol.None,
  39. BackupLatency: 10 * time.Millisecond,
  40. }
  41. sd := client.NewPeer2PeerDiscovery(fmt.Sprintf("tcp@%s:%s", k8sServiceName, k8sServicePort), "")
  42. a.xcli = client.NewXClient(servicePath, client.Failtry, client.RandomSelect, sd, opt)
  43. }
  44. func (a *GdAuthCheckXClient) ManagementCheckApi(ctx context.Context, req *apis.ManagementCheckApiReq) (reply apis.ManagementCheckApiReply, err error) {
  45. err = a.xcli.Call(ctx, "ManagementCheckApi", req, &reply)
  46. return
  47. }
  48. func (a *GdAuthCheckXClient) ManagementThirdpartCountIncrease(ctx context.Context, req *apis.ManagementThirdpartCountIncreaseReq) (reply apis.ManagementThirdpartCountIncreaseReply, err error) {
  49. err = a.xcli.Call(ctx, "ManagementThirdpartCountIncrease", req, &reply)
  50. return
  51. }
  52. func (a *GdAuthCheckXClient) ManagementCheckCountCode(ctx context.Context, req *apis.ManagementCheckCountCodeReq) (reply apis.ManagementCheckCountCodeReply, err error) {
  53. err = a.xcli.Call(ctx, "ManagementCheckCountCode", req, &reply)
  54. return
  55. }
  56. func (a *GdAuthCheckXClient) ReleaseToken(ctx context.Context, req *apis.RateLimitToken) (reply apis.RateLimitToken, err error) {
  57. err = a.xcli.Call(ctx, "ReleaseToken", req, &reply)
  58. return
  59. }
  60. func (a *GdAuthCheckXClient) MerchantAppLogin(ctx context.Context, req *apis.MerchantAppLoginReq) (reply apis.MerchantAppLoginReply, err error) {
  61. err = a.xcli.Call(ctx, "MerchantAppLogin", req, &reply)
  62. return
  63. }