entmanageapplication.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package middleground
  2. import (
  3. "context"
  4. "log"
  5. "bp.jydev.jianyu360.cn/BaseService/entManageApplication/rpc/entmanageapplication"
  6. "bp.jydev.jianyu360.cn/BaseService/entManageApplication/rpc/pb"
  7. "github.com/zeromicro/go-zero/core/discov"
  8. "github.com/zeromicro/go-zero/zrpc"
  9. )
  10. type entManageApplication struct {
  11. hosts []string
  12. key string
  13. client zrpc.Client
  14. }
  15. func newEntManageApplication(hosts []string, key string) *entManageApplication {
  16. r := &entManageApplication{
  17. hosts: hosts,
  18. key: key,
  19. }
  20. r.client = r.NewClient()
  21. return r
  22. }
  23. func (e *entManageApplication) NewClient() zrpc.Client {
  24. if e.client != nil && e.client.Conn() != nil {
  25. return e.client
  26. }
  27. client, err := zrpc.NewClient(zrpc.RpcClientConf{
  28. Etcd: discov.EtcdConf{
  29. Hosts: e.hosts,
  30. Key: e.key,
  31. },
  32. })
  33. if err != nil {
  34. log.Println(err)
  35. return nil
  36. }
  37. e.client = client
  38. return client
  39. }
  40. //
  41. func (e *entManageApplication) EmpowerUserIds(ids []int64) *pb.EmpowerUserIds {
  42. client := e.NewClient()
  43. if client == nil {
  44. return nil
  45. }
  46. //defer client.Conn().Close()
  47. resp, err := entmanageapplication.NewEntManageApplication(client).EmpowerUserIds(context.Background(), &pb.EmpowerUserIds{
  48. Ids: ids,
  49. })
  50. if err != nil {
  51. log.Println(err)
  52. return nil
  53. }
  54. return resp
  55. }