ecode.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/http"
  6. "net/url"
  7. "go-common/app/admin/main/apm/model/ecode"
  8. "go-common/library/log"
  9. )
  10. // const (
  11. // _codesLangsSQL = "select a.code,a.message,a.mtime,IFNULL(b.locale,''),IFNULL(b.msg,''),IFNULL(b.mtime,'') as bmtime from codes as a left join code_msg as b on a.id=b.code_id"
  12. // )
  13. // GetCodes ...
  14. func (d *Dao) GetCodes(c context.Context, Interval1, Interval2 string) (data []*codes.Codes, err error) {
  15. var (
  16. req *http.Request
  17. uri = "http://sven.bilibili.co/x/admin/apm/ecode/get/ecodes"
  18. ret = codes.ResultCodes{}
  19. params = url.Values{}
  20. )
  21. params.Set("interval1", Interval1)
  22. params.Set("interval2", Interval2)
  23. if req, err = d.client.NewRequest(http.MethodGet, uri, "", params); err != nil {
  24. log.Error("http.NewRequest error(%v)", err)
  25. return
  26. }
  27. if err = d.client.Do(c, req, &ret); err != nil {
  28. log.Error("client Do error(%v)", err)
  29. return
  30. }
  31. if ret.Code != 0 {
  32. err = fmt.Errorf("%s params(%s) response return_code(%d)", uri, params.Encode(), ret.Code)
  33. log.Error("error(%v)", err)
  34. return
  35. }
  36. data = ret.Data
  37. return
  38. }