service.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/bbq/app-bbq/conf"
  5. "go-common/app/interface/bbq/app-bbq/dao"
  6. "go-common/library/log"
  7. topic "go-common/app/service/bbq/topic/api"
  8. video_v1 "go-common/app/service/bbq/video/api/grpc/v1"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/rpc/warden"
  11. )
  12. // Service struct
  13. type Service struct {
  14. c *conf.Config
  15. dao *dao.Dao
  16. videoClient video_v1.VideoClient
  17. topicClient topic.TopicClient
  18. httpClient *bm.Client
  19. }
  20. // New init
  21. func New(c *conf.Config) (s *Service) {
  22. s = &Service{
  23. c: c,
  24. dao: dao.New(c),
  25. videoClient: newVideoClient(c.GRPCClient["video"]),
  26. httpClient: bm.NewClient(c.HTTPClient.Normal),
  27. }
  28. var err error
  29. if s.topicClient, err = topic.NewClient(nil); err != nil {
  30. log.Errorw(context.Background(), "log", "get topic client fail")
  31. panic(err)
  32. }
  33. return s
  34. }
  35. // newVideoClient .
  36. func newVideoClient(cfg *conf.GRPCConf) video_v1.VideoClient {
  37. cc, err := warden.NewClient(cfg.WardenConf).Dial(context.Background(), cfg.Addr)
  38. if err != nil {
  39. panic(err)
  40. }
  41. return video_v1.NewVideoClient(cc)
  42. }
  43. // Ping Service
  44. func (s *Service) Ping(c context.Context) (err error) {
  45. return s.dao.Ping(c)
  46. }
  47. // Close Service
  48. func (s *Service) Close() {
  49. s.dao.Close()
  50. }
  51. func buvid(device *bm.Device) string {
  52. // if device.RawMobiApp == "" {
  53. // return device.Buvid3
  54. // }
  55. return device.Buvid
  56. }