dao.go 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package vip
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/app-intl/conf"
  7. "go-common/library/ecode"
  8. httpx "go-common/library/net/http/blademaster"
  9. "github.com/pkg/errors"
  10. )
  11. const (
  12. _vipActive = "/internal/v1/notice/active"
  13. )
  14. // Dao is vip dao.
  15. type Dao struct {
  16. client *httpx.Client
  17. vipActiveURL string
  18. }
  19. // New vip dao.
  20. func New(c *conf.Config) (d *Dao) {
  21. d = &Dao{
  22. client: httpx.NewClient(c.HTTPWrite),
  23. // api
  24. vipActiveURL: c.Host.VIP + _vipActive,
  25. }
  26. return
  27. }
  28. // VIPActive get vip active info.
  29. func (d *Dao) VIPActive(c context.Context, subID int) (msg string, err error) {
  30. params := url.Values{}
  31. params.Set("subId", strconv.Itoa(subID))
  32. var res struct {
  33. Code int `json:"code"`
  34. Data string `json:"data"`
  35. }
  36. if err = d.client.Get(c, d.vipActiveURL, "", params, &res); err != nil {
  37. return
  38. }
  39. if res.Code != ecode.OK.Code() {
  40. err = errors.Wrap(ecode.Int(res.Code), d.vipActiveURL+"?"+params.Encode())
  41. return
  42. }
  43. msg = res.Data
  44. return
  45. }