space.go 879 B

123456789101112131415161718192021222324252627282930313233343536
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/web/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. )
  11. // TopPhoto getTopPhoto from space
  12. func (d *Dao) TopPhoto(c context.Context, mid int64) (space *model.Space, err error) {
  13. var (
  14. params = url.Values{}
  15. remoteIP = metadata.String(c, metadata.RemoteIP)
  16. )
  17. params.Set("mid", strconv.FormatInt(mid, 10))
  18. var res struct {
  19. Code int `json:"code"`
  20. model.Space
  21. }
  22. if err = d.httpR.Get(c, d.spaceTopPhotoURL, remoteIP, params, &res); err != nil {
  23. log.Error("TopPhoto space url(%s) error(%v)", d.spaceTopPhotoURL+"?"+params.Encode(), err)
  24. return
  25. }
  26. if res.Code != 0 {
  27. log.Error("TopPhoto space url(%s) error(%v)", d.spaceTopPhotoURL+"?"+params.Encode(), res.Code)
  28. err = ecode.Int(res.Code)
  29. return
  30. }
  31. space = &res.Space
  32. return
  33. }