service.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package v2
  2. import (
  3. "context"
  4. "sync"
  5. "go-common/app/infra/config/conf"
  6. "go-common/app/infra/config/dao/v2"
  7. "go-common/app/infra/config/model"
  8. xtime "go-common/library/time"
  9. )
  10. // Service service.
  11. type Service struct {
  12. dao *v2.Dao
  13. PollTimeout xtime.Duration
  14. //config2 app
  15. aLock sync.RWMutex
  16. bLock sync.RWMutex
  17. apps map[string]*model.App
  18. services map[string]*model.App
  19. //config2 tags
  20. tLock sync.RWMutex
  21. tags map[string]*curTag
  22. eLock sync.RWMutex
  23. events map[string]chan *model.Diff
  24. //force version
  25. fLock sync.RWMutex
  26. forces map[string]int64
  27. //config2 tag force
  28. tfLock sync.RWMutex
  29. forceType map[string]int8
  30. // config2 tagID
  31. tagIDLock sync.RWMutex
  32. tagID map[string]int64
  33. //config2 last force version
  34. lfvLock sync.RWMutex
  35. lfvforces map[string]int64
  36. }
  37. // New new a service.
  38. func New(c *conf.Config) (s *Service) {
  39. s = new(Service)
  40. s.dao = v2.New(c)
  41. s.PollTimeout = c.PollTimeout
  42. s.tags = make(map[string]*curTag)
  43. s.apps = make(map[string]*model.App)
  44. s.services = make(map[string]*model.App)
  45. s.events = make(map[string]chan *model.Diff)
  46. s.forces = make(map[string]int64)
  47. s.forceType = make(map[string]int8)
  48. s.tagID = make(map[string]int64)
  49. s.lfvforces = make(map[string]int64)
  50. return
  51. }
  52. // Ping check is ok.
  53. func (s *Service) Ping(c context.Context) (err error) {
  54. return s.dao.Ping(c)
  55. }
  56. // Close close resources.
  57. func (s *Service) Close() {
  58. s.dao.Close()
  59. }