topic.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package notice
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/library/log"
  8. )
  9. // Topic return topic link.
  10. func (d *Dao) Topic(c context.Context, oid int64) (title, link string, err error) {
  11. params := url.Values{}
  12. uri := fmt.Sprintf(d.urlTopic, oid)
  13. var res struct {
  14. Code int `json:"code"`
  15. Data *struct {
  16. Title string `json:"name"`
  17. PCLink string `json:"pc_url"`
  18. H5Link string `json:"h5_url"`
  19. } `json:"data"`
  20. }
  21. if err = d.httpClient.Get(c, uri, "", params, &res); err != nil {
  22. log.Error("d.httpClient.Get(%s?%s) error(%v)", uri, params.Encode(), err)
  23. return
  24. }
  25. if res.Data == nil {
  26. err = fmt.Errorf("url:%s code:%d", uri, res.Code)
  27. return
  28. }
  29. title = res.Data.Title
  30. link = res.Data.PCLink
  31. if link == "" {
  32. link = res.Data.H5Link
  33. }
  34. return
  35. }
  36. // Activity return topic link.
  37. func (d *Dao) Activity(c context.Context, oid int64) (title, link string, err error) {
  38. params := url.Values{}
  39. uri := fmt.Sprintf(d.urlActivity, oid)
  40. var res struct {
  41. Code int `json:"code"`
  42. Data *struct {
  43. Title string `json:"name"`
  44. PCLink string `json:"pc_url"`
  45. H5Link string `json:"h5_url"`
  46. } `json:"data"`
  47. }
  48. if err = d.httpClient.Get(c, uri, "", params, &res); err != nil {
  49. log.Error("d.httpClient.Get(%s?%s) error(%v)", uri, params.Encode(), err)
  50. return
  51. }
  52. if res.Data == nil {
  53. err = fmt.Errorf("url:%s code:%d", uri, res.Code)
  54. return
  55. }
  56. title = res.Data.Title
  57. link = res.Data.PCLink
  58. if link == "" {
  59. link = res.Data.H5Link
  60. }
  61. return
  62. }
  63. // ActivitySub return topic link.
  64. func (d *Dao) ActivitySub(c context.Context, oid int64) (title, link string, err error) {
  65. params := url.Values{}
  66. params.Set("oid", strconv.FormatInt(oid, 10))
  67. var res struct {
  68. Code int `json:"code"`
  69. Data *struct {
  70. Title string `json:"name"`
  71. Link string `json:"act_url"`
  72. } `json:"data"`
  73. }
  74. if err = d.httpClient.Get(c, d.urlActivitySub, "", params, &res); err != nil {
  75. log.Error("d.httpClient.Get(%s?%s) error(%v)", d.urlActivitySub, params.Encode(), err)
  76. return
  77. }
  78. if res.Data == nil {
  79. err = fmt.Errorf("url:%s code:%d", d.urlActivitySub, res.Code)
  80. return
  81. }
  82. title = res.Data.Title
  83. link = res.Data.Link
  84. return
  85. }