123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package notice
- import (
- "context"
- "fmt"
- "net/url"
- "strconv"
- "go-common/library/log"
- )
- // Topic return topic link.
- func (d *Dao) Topic(c context.Context, oid int64) (title, link string, err error) {
- params := url.Values{}
- uri := fmt.Sprintf(d.urlTopic, oid)
- var res struct {
- Code int `json:"code"`
- Data *struct {
- Title string `json:"name"`
- PCLink string `json:"pc_url"`
- H5Link string `json:"h5_url"`
- } `json:"data"`
- }
- if err = d.httpClient.Get(c, uri, "", params, &res); err != nil {
- log.Error("d.httpClient.Get(%s?%s) error(%v)", uri, params.Encode(), err)
- return
- }
- if res.Data == nil {
- err = fmt.Errorf("url:%s code:%d", uri, res.Code)
- return
- }
- title = res.Data.Title
- link = res.Data.PCLink
- if link == "" {
- link = res.Data.H5Link
- }
- return
- }
- // Activity return topic link.
- func (d *Dao) Activity(c context.Context, oid int64) (title, link string, err error) {
- params := url.Values{}
- uri := fmt.Sprintf(d.urlActivity, oid)
- var res struct {
- Code int `json:"code"`
- Data *struct {
- Title string `json:"name"`
- PCLink string `json:"pc_url"`
- H5Link string `json:"h5_url"`
- } `json:"data"`
- }
- if err = d.httpClient.Get(c, uri, "", params, &res); err != nil {
- log.Error("d.httpClient.Get(%s?%s) error(%v)", uri, params.Encode(), err)
- return
- }
- if res.Data == nil {
- err = fmt.Errorf("url:%s code:%d", uri, res.Code)
- return
- }
- title = res.Data.Title
- link = res.Data.PCLink
- if link == "" {
- link = res.Data.H5Link
- }
- return
- }
- // ActivitySub return topic link.
- func (d *Dao) ActivitySub(c context.Context, oid int64) (title, link string, err error) {
- params := url.Values{}
- params.Set("oid", strconv.FormatInt(oid, 10))
- var res struct {
- Code int `json:"code"`
- Data *struct {
- Title string `json:"name"`
- Link string `json:"act_url"`
- } `json:"data"`
- }
- if err = d.httpClient.Get(c, d.urlActivitySub, "", params, &res); err != nil {
- log.Error("d.httpClient.Get(%s?%s) error(%v)", d.urlActivitySub, params.Encode(), err)
- return
- }
- if res.Data == nil {
- err = fmt.Errorf("url:%s code:%d", d.urlActivitySub, res.Code)
- return
- }
- title = res.Data.Title
- link = res.Data.Link
- return
- }
|