service.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/main/identify/conf"
  5. "go-common/app/job/main/identify/dao"
  6. "go-common/app/job/main/identify/model"
  7. "go-common/library/cache/memcache"
  8. "go-common/library/queue/databus"
  9. "go-common/library/queue/databus/databusutil"
  10. )
  11. const (
  12. _tokenTable = "aso_app_perm"
  13. _cookieTable = "aso_cookie_token"
  14. _insertAction = "insert"
  15. _delteAction = "delete"
  16. )
  17. var (
  18. _gameAppID = [3]int64{432, 876, 849}
  19. )
  20. // Service is a identify service.
  21. type Service struct {
  22. c *conf.Config
  23. d *dao.Dao
  24. identifySub *databus.Databus
  25. authDataBus *databus.Databus
  26. // mc
  27. poolm map[string]*memcache.Pool
  28. // databus group
  29. authGroup *databusutil.Group
  30. identifyGroup *databusutil.Group
  31. cookieCh []chan *model.AuthCookie
  32. tokenCh []chan *model.AuthToken
  33. }
  34. // New new a identify service.
  35. func New(c *conf.Config) (s *Service) {
  36. s = &Service{
  37. c: c,
  38. d: dao.New(c),
  39. identifySub: databus.New(c.DataBus.IdentifySub),
  40. authDataBus: databus.New(c.DataBus.AuthDataBus),
  41. cookieCh: make([]chan *model.AuthCookie, c.CheckConf.ChanNum),
  42. tokenCh: make([]chan *model.AuthToken, c.CheckConf.ChanNum),
  43. }
  44. if len(s.c.Memcaches) > 0 {
  45. pm := make(map[string]*memcache.Pool, len(s.c.Memcaches))
  46. for name, mcc := range s.c.Memcaches {
  47. p := memcache.NewPool(mcc.Config)
  48. pm[name] = p
  49. }
  50. s.poolm = pm
  51. }
  52. s.authGroup = databusutil.NewGroup(c.Databusutil, s.authDataBus.Messages())
  53. s.authGroup.New = s.new
  54. s.authGroup.Split = s.spilt
  55. s.authGroup.Do = s.processAuthBinlog2
  56. s.authGroup.Start()
  57. s.identifyGroup = databusutil.NewGroup(c.Databusutil, s.identifySub.Messages())
  58. s.identifyGroup.New = s.identifyNew
  59. s.identifyGroup.Split = s.identifySplit
  60. s.identifyGroup.Do = s.processIdentifyInfo
  61. s.identifyGroup.Start()
  62. if c.CheckConf.Switch {
  63. for i := 0; i < c.CheckConf.ChanNum; i++ {
  64. cookie := make(chan *model.AuthCookie, c.CheckConf.ChanSize)
  65. token := make(chan *model.AuthToken, c.CheckConf.ChanSize)
  66. s.cookieCh[i] = cookie
  67. s.tokenCh[i] = token
  68. go s.checkCookie(cookie)
  69. go s.checkToken(token)
  70. }
  71. go s.queryCookieDeleted()
  72. go s.queryTokenDeleted()
  73. }
  74. return
  75. }
  76. // Ping .
  77. func (s *Service) Ping(c context.Context) (err error) {
  78. return nil
  79. }
  80. // Close close.
  81. func (s *Service) Close() (err error) {
  82. s.identifySub.Close()
  83. s.authDataBus.Close()
  84. s.authGroup.Close()
  85. s.identifyGroup.Close()
  86. return nil
  87. }