service.go 914 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package v1
  2. import (
  3. "context"
  4. "sync"
  5. "go-common/app/infra/config/conf"
  6. "go-common/app/infra/config/dao/v1"
  7. "go-common/app/infra/config/model"
  8. xtime "go-common/library/time"
  9. )
  10. // Service service.
  11. type Service struct {
  12. dao *v1.Dao
  13. vLock sync.RWMutex
  14. versions map[string]int64 // serviceName_buildVersion > configVersion
  15. eLock sync.RWMutex
  16. events map[string]chan *model.Version
  17. PollTimeout xtime.Duration
  18. token map[string]string
  19. }
  20. // New new a service.
  21. func New(c *conf.Config) (s *Service) {
  22. s = new(Service)
  23. s.dao = v1.New(c)
  24. s.versions = make(map[string]int64)
  25. s.events = make(map[string]chan *model.Version)
  26. s.PollTimeout = c.PollTimeout
  27. s.token = make(map[string]string)
  28. return
  29. }
  30. // Ping check is ok.
  31. func (s *Service) Ping(c context.Context) (err error) {
  32. return s.dao.Ping(c)
  33. }
  34. // Close close resources.
  35. func (s *Service) Close() {
  36. s.dao.Close()
  37. }