dao.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package porder
  2. import (
  3. "context"
  4. "go-common/app/interface/main/creative/conf"
  5. "go-common/app/interface/main/creative/model/porder"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. httpx "go-common/library/net/http/blademaster"
  9. "net/url"
  10. )
  11. const (
  12. _porderConfig = "/videoup/porder/config/list"
  13. )
  14. // Dao define
  15. type Dao struct {
  16. c *conf.Config
  17. // http
  18. client *httpx.Client
  19. // uri
  20. porderConfigURL string
  21. }
  22. // New init dao
  23. func New(c *conf.Config) (d *Dao) {
  24. d = &Dao{
  25. c: c,
  26. client: httpx.NewClient(c.HTTPClient.Normal),
  27. porderConfigURL: c.Host.Videoup + _porderConfig,
  28. }
  29. return
  30. }
  31. // ListConfig fn
  32. func (d *Dao) ListConfig(c context.Context) (cfgs []*porder.Config, err error) {
  33. params := url.Values{}
  34. var res struct {
  35. Code int `json:"code"`
  36. Cfgs []*porder.Config `json:"data"`
  37. }
  38. if err = d.client.Get(c, d.porderConfigURL, "", params, &res); err != nil {
  39. log.Error("ListConfig url(%s) response(%+v) error(%v)", d.porderConfigURL+"?"+params.Encode(), res, err)
  40. err = ecode.CreativeArchiveAPIErr
  41. return
  42. }
  43. log.Info("ListConfig url(%s)", d.porderConfigURL+"?"+params.Encode())
  44. if res.Code != 0 {
  45. log.Error("ListConfig url(%s) res(%v)", d.porderConfigURL, res)
  46. err = ecode.CreativeArchiveAPIErr
  47. return
  48. }
  49. cfgs = res.Cfgs
  50. return
  51. }