archive.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/interface/main/videoup/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _typesURL = "/videoup/types"
  11. )
  12. func (d *Dao) typesURI() string {
  13. return d.conf.Host.Archive + _typesURL
  14. }
  15. // TypeMapping is second types opposite first types.
  16. func (d *Dao) TypeMapping(c context.Context) (rmap map[int16]int16, err error) {
  17. var res struct {
  18. Code int `json:"code"`
  19. Message string `json:"message"`
  20. Data map[int16]*archive.Type `json:"data"`
  21. }
  22. if err = d.httpCli.Get(c, d.typesURI(), "", nil, &res); err != nil {
  23. log.Error("d.httpCli.Get() error(%v) typesURI(%s)", err, d.typesURI())
  24. return
  25. }
  26. if res.Code != ecode.OK.Code() {
  27. err = fmt.Errorf("bangumi seasons api failed(%d)", res.Code)
  28. log.Error("url(%s) res code(%d)", d.typesURI(), res.Code)
  29. return
  30. }
  31. rmap = make(map[int16]int16, len(res.Data))
  32. for _, v := range res.Data {
  33. if v.PID != 0 {
  34. rmap[v.ID] = v.PID
  35. }
  36. }
  37. return
  38. }