resourcecenter.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package middleground
  2. import (
  3. "context"
  4. "log"
  5. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/pb"
  6. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/rpc/resource"
  7. "github.com/zeromicro/go-zero/core/discov"
  8. "github.com/zeromicro/go-zero/zrpc"
  9. )
  10. type resourceCenter struct {
  11. hosts []string
  12. key string
  13. }
  14. func newResourceCenter(hosts []string, key string) *resourceCenter {
  15. return &resourceCenter{
  16. hosts: hosts,
  17. key: key,
  18. }
  19. }
  20. func (r *resourceCenter) newClient() zrpc.Client {
  21. client, err := zrpc.NewClient(zrpc.RpcClientConf{
  22. Etcd: discov.EtcdConf{
  23. Hosts: r.hosts,
  24. Key: r.key,
  25. },
  26. })
  27. if err != nil {
  28. log.Println(err)
  29. return nil
  30. }
  31. return client
  32. }
  33. //
  34. func (r *resourceCenter) Haspowers(accountId, entAccountId, entId, entUserId int64) *pb.HaspowersResp {
  35. client := r.newClient()
  36. if client == nil {
  37. return nil
  38. }
  39. defer client.Conn().Close()
  40. resp, err := resource.NewResource(client).Haspowers(context.Background(), &pb.HaspowersReq{
  41. Appid: "10000",
  42. AccountId: accountId,
  43. EntAccountId: entAccountId,
  44. EntId: entId,
  45. EntUserId: entUserId,
  46. })
  47. if err != nil {
  48. log.Println(err)
  49. return nil
  50. }
  51. return resp
  52. }