service.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/activity/conf"
  5. "go-common/app/admin/main/activity/dao"
  6. tagrpc "go-common/app/interface/main/tag/rpc/client"
  7. artrpc "go-common/app/interface/openplatform/article/rpc/client"
  8. acccli "go-common/app/service/main/account/api"
  9. arcclient "go-common/app/service/main/archive/api"
  10. "github.com/jinzhu/gorm"
  11. )
  12. // Service biz service def.
  13. type Service struct {
  14. c *conf.Config
  15. dao *dao.Dao
  16. DB *gorm.DB
  17. accClient acccli.AccountClient
  18. tagRPC *tagrpc.Service
  19. artRPC *artrpc.Service
  20. arcClient arcclient.ArchiveClient
  21. }
  22. // New new a Service and return.
  23. func New(c *conf.Config) (s *Service) {
  24. s = &Service{
  25. c: c,
  26. dao: dao.New(c),
  27. tagRPC: tagrpc.New2(c.TagRPC),
  28. artRPC: artrpc.New(c.ArticlrRPC),
  29. }
  30. s.DB = s.dao.DB
  31. var err error
  32. if s.arcClient, err = arcclient.NewClient(c.ArcClient); err != nil {
  33. panic(err)
  34. }
  35. if s.accClient, err = acccli.NewClient(c.AccClient); err != nil {
  36. panic(err)
  37. }
  38. return s
  39. }
  40. // Ping check dao health.
  41. func (s *Service) Ping(c context.Context) (err error) {
  42. return s.dao.Ping(c)
  43. }
  44. // Wait wait all closed.
  45. func (s *Service) Wait() {}
  46. // Close close all dao.
  47. func (s *Service) Close() {
  48. s.dao.Close()
  49. }