service.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package goblin
  2. import (
  3. "context"
  4. "go-common/app/interface/main/tv/conf"
  5. "go-common/app/interface/main/tv/dao/account"
  6. "go-common/app/interface/main/tv/dao/archive"
  7. gobDao "go-common/app/interface/main/tv/dao/goblin"
  8. "go-common/app/interface/main/tv/model"
  9. "go-common/app/interface/main/tv/model/goblin"
  10. tvapi "go-common/app/service/main/tv/api"
  11. )
  12. // Service .
  13. type Service struct {
  14. conf *conf.Config
  15. dao *gobDao.Dao
  16. accDao *account.Dao
  17. arcDao *archive.Dao
  18. ChlSplash map[string]string // channel's splash data
  19. Hotword []*model.Hotword // search hotword data
  20. VipQns map[string]int // playurl qualities for vips
  21. labels *goblin.IndexLabels
  22. tvCilent tvapi.TVServiceClient
  23. }
  24. var ctx = context.TODO()
  25. // New .
  26. func New(c *conf.Config) *Service {
  27. srv := &Service{
  28. conf: c,
  29. dao: gobDao.New(c),
  30. ChlSplash: make(map[string]string),
  31. VipQns: make(map[string]int),
  32. accDao: account.New(c),
  33. arcDao: archive.New(c),
  34. labels: &goblin.IndexLabels{},
  35. }
  36. var err error
  37. if srv.tvCilent, err = tvapi.NewClient(c.TvVipClient); err != nil {
  38. panic(err)
  39. }
  40. for _, v := range c.Cfg.VipQns {
  41. srv.VipQns[v] = 1
  42. }
  43. go srv.loadSph() // splash
  44. go srv.loadHotword() // hotword
  45. go srv.loadSphproc() // splash proc
  46. go srv.loadHotwordproc() // hotword proc
  47. srv.prepareLabels() // prepare index labels
  48. go srv.labelsproc()
  49. return srv
  50. }