task_http.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "go-common/app/job/main/aegis/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _addURL = "/x/internal/aegis/add"
  11. _updateURL = "/x/internal/aegis/update"
  12. _cancelURL = "/x/internal/aegis/cancel"
  13. )
  14. //RscAdd resource add
  15. func (d *Dao) RscAdd(c context.Context, opt *model.AddOption) error {
  16. uri := d.c.Host.API + _addURL
  17. params := opt.ToQueryURI()
  18. return d.commonPost(c, uri, params)
  19. }
  20. //RscUpdate resource update
  21. func (d *Dao) RscUpdate(c context.Context, opt *model.UpdateOption) error {
  22. uri := d.c.Host.API + _updateURL
  23. params := opt.ToQueryURI()
  24. return d.commonPost(c, uri, params)
  25. }
  26. //RscCancel resource cancel
  27. func (d *Dao) RscCancel(c context.Context, opt *model.CancelOption) error {
  28. uri := d.c.Host.API + _cancelURL
  29. params := opt.ToQueryURI()
  30. return d.commonPost(c, uri, params)
  31. }
  32. func (d *Dao) commonPost(c context.Context, uri string, params url.Values) error {
  33. res := new(model.BaseResponse)
  34. if err := d.httpFast.Post(c, uri, "", params, res); err != nil {
  35. log.Error("d.httpFast.Post(%s) params(%s) error(%v)", uri, params.Encode(), err)
  36. return err
  37. }
  38. if res.Code != 0 {
  39. log.Error("d.httpFast.Post(%s) params(%s) res(%+v)", uri, params.Encode(), res)
  40. return ecode.Code(res.Code)
  41. }
  42. return nil
  43. }