dapper.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package dao
  2. import (
  3. "context"
  4. "net/http"
  5. "go-common/app/admin/ep/melloi/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _dapperDependUri = "/x/internal/dapper/service-depend?service_name="
  11. _dapperRspCode = 0
  12. )
  13. // QueryServiceDepend query service depend
  14. func (d *Dao) QueryServiceDepend(c context.Context, serviceName string) (ret []string, err error) {
  15. var (
  16. req *http.Request
  17. DependURL = d.c.Dapper.Host + _dapperDependUri + serviceName
  18. res struct {
  19. Code int `json:"code"`
  20. Data *model.DependResponse `json:"data"`
  21. Message string `json:"message"`
  22. }
  23. )
  24. if req, err = d.newRequest(http.MethodGet, DependURL, nil); err != nil {
  25. return
  26. }
  27. if err = d.httpClient.Do(c, req, &res); err != nil {
  28. log.Error("d.Depend url(%s) res($s) error(%v)", DependURL, res, err)
  29. return
  30. }
  31. if res.Code != _dapperRspCode {
  32. err = ecode.MelloiTreeRequestErr
  33. log.Error("d.Tree.Response url(%s) resCode(%s) error(%v)", DependURL, res.Code, err)
  34. return
  35. }
  36. for _, item := range res.Data.Items {
  37. ret = append(ret, item.ServiceName)
  38. }
  39. return
  40. }