service.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/admin/main/reply/conf"
  6. "go-common/app/admin/main/reply/dao"
  7. artrpc "go-common/app/interface/openplatform/article/rpc/client"
  8. accrpc "go-common/app/service/main/account/api"
  9. arcrpc "go-common/app/service/main/archive/api/gorpc"
  10. rlrpc "go-common/app/service/main/relation/rpc/client"
  11. thumbup "go-common/app/service/main/thumbup/api"
  12. bm "go-common/library/net/http/blademaster"
  13. "go-common/library/net/rpc/warden"
  14. "go-common/library/sync/pipeline/fanout"
  15. )
  16. // Service is a service.
  17. type Service struct {
  18. conf *conf.Config
  19. dao *dao.Dao
  20. httpClient *bm.Client
  21. accSrv accrpc.AccountClient
  22. arcSrv *arcrpc.Service2
  23. articleSrv *artrpc.Service
  24. cache *fanout.Fanout
  25. thumbupClient thumbup.ThumbupClient
  26. relationSvc *rlrpc.Service
  27. // 特殊admin,针对大忽悠事件消息通知
  28. ads map[string]struct{}
  29. // 特殊稿件,针对大忽悠时间 不让删评论
  30. oids map[int64]int32
  31. // mark folded or unmark folded worker
  32. marker *fanout.Fanout
  33. // del cache or add cache worker
  34. cacheOperater *fanout.Fanout
  35. }
  36. // New new a service and return.
  37. func New(c *conf.Config) (s *Service) {
  38. s = &Service{
  39. conf: c,
  40. dao: dao.New(c),
  41. httpClient: bm.NewClient(c.HTTPClient),
  42. arcSrv: arcrpc.New2(c.RPCClient2.Archive),
  43. articleSrv: artrpc.New(c.RPCClient2.Article),
  44. cache: fanout.New("cache", fanout.Worker(1), fanout.Buffer(1024*10)),
  45. relationSvc: rlrpc.New(c.RPCClient2.Relation),
  46. marker: fanout.New("marker", fanout.Worker(1), fanout.Buffer(1024*10)),
  47. cacheOperater: fanout.New("cacheOp", fanout.Worker(1), fanout.Buffer(1024*10)),
  48. }
  49. accSrv, err := accrpc.NewClient(c.AccountClient)
  50. if err != nil {
  51. panic(err)
  52. }
  53. s.accSrv = accSrv
  54. cc, err := warden.NewConn(fmt.Sprintf("discovery://default/%s", thumbup.AppID))
  55. if err != nil {
  56. panic(err)
  57. }
  58. s.thumbupClient = thumbup.NewThumbupClient(cc)
  59. ads := make(map[string]struct{})
  60. for _, ID := range c.Reply.AdminName {
  61. ads[ID] = struct{}{}
  62. }
  63. s.ads = ads
  64. oids := make(map[int64]int32)
  65. for i, oid := range c.Reply.Oids {
  66. oids[oid] = c.Reply.Tps[i]
  67. }
  68. s.oids = oids
  69. return
  70. }
  71. // Ping check service is ok.
  72. func (s *Service) Ping(c context.Context) (err error) {
  73. return s.dao.Ping(c)
  74. }