service.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/mcn/conf"
  5. bfs "go-common/app/admin/main/mcn/dao/bfs"
  6. msg "go-common/app/admin/main/mcn/dao/msg"
  7. dao "go-common/app/admin/main/mcn/dao/up"
  8. videoup "go-common/app/admin/main/mcn/dao/videoup"
  9. "go-common/app/admin/main/mcn/model"
  10. "go-common/app/interface/main/mcn/tool/worker"
  11. accgrpc "go-common/app/service/main/account/api"
  12. arcgrpc "go-common/app/service/main/archive/api"
  13. memgrpc "go-common/app/service/main/member/api"
  14. "github.com/pkg/errors"
  15. )
  16. // Service struct
  17. type Service struct {
  18. c *conf.Config
  19. dao *dao.Dao
  20. bfs *bfs.Dao
  21. msg *msg.Dao
  22. videoup *videoup.Dao
  23. msgMap map[model.MSGType]*model.MSG
  24. memGRPC memgrpc.MemberClient
  25. accGRPC accgrpc.AccountClient
  26. arcGRPC arcgrpc.ArchiveClient
  27. worker *worker.Pool
  28. }
  29. // New init
  30. func New(c *conf.Config) (s *Service) {
  31. s = &Service{
  32. c: c,
  33. dao: dao.New(c),
  34. bfs: bfs.New(c),
  35. msg: msg.New(c),
  36. videoup: videoup.New(c),
  37. worker: worker.New(nil),
  38. }
  39. var err error
  40. if s.accGRPC, err = accgrpc.NewClient(c.GRPCClient.Account); err != nil {
  41. panic(errors.WithMessage(err, "Failed to dial account service"))
  42. }
  43. if s.arcGRPC, err = arcgrpc.NewClient(c.GRPCClient.Archive); err != nil {
  44. panic(errors.WithMessage(err, "Failed to dial archive service"))
  45. }
  46. if s.memGRPC, err = memgrpc.NewClient(c.GRPCClient.Member); err != nil {
  47. panic(errors.WithMessage(err, "Failed to dial member service"))
  48. }
  49. s.setMsgTypeMap()
  50. return s
  51. }
  52. // Ping Service
  53. func (s *Service) Ping(c context.Context) (err error) {
  54. return s.dao.Ping(c)
  55. }
  56. // Close Service
  57. func (s *Service) Close() {
  58. s.dao.Close()
  59. s.worker.Close()
  60. s.worker.Wait()
  61. }