drawyoo.go 797 B

1234567891011121314151617181920212223242526272829303132333435
  1. package notice
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/library/log"
  8. )
  9. // Drawyoo return link.
  10. func (d *Dao) Drawyoo(c context.Context, hid int64) (title, link string, err error) {
  11. params := url.Values{}
  12. params.Set("hid", strconv.FormatInt(hid, 10))
  13. params.Set("act", "getHidInfo")
  14. var res struct {
  15. State int `json:"state"`
  16. Data []*struct {
  17. Title string `json:"title"`
  18. Link string `json:"link"`
  19. } `json:"data"`
  20. }
  21. if err = d.drawyooHTTPClient.Post(c, d.urlDrwayoo, "", params, &res); err != nil {
  22. log.Error("d.httpClient.Get(%s?%s) error(%v)", d.urlDrwayoo, params.Encode(), err)
  23. return
  24. }
  25. if len(res.Data) == 0 {
  26. err = fmt.Errorf("url:%s code:%d", d.urlDrwayoo, res.State)
  27. return
  28. }
  29. title = res.Data[0].Title
  30. link = res.Data[0].Link
  31. return
  32. }