operator.go 784 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package operator
  2. import (
  3. "time"
  4. "go-common/app/interface/main/app-wall/conf"
  5. "go-common/app/interface/main/app-wall/model/operator"
  6. )
  7. // Service reddot service
  8. type Service struct {
  9. c *conf.Config
  10. cache *operator.Reddot
  11. }
  12. // New reddot new
  13. func New(c *conf.Config) (s *Service) {
  14. s = &Service{
  15. c: c,
  16. cache: &operator.Reddot{},
  17. }
  18. s.loadCache(c)
  19. return
  20. }
  21. // Reddot get reddot
  22. func (s *Service) Reddot(now time.Time) (res *operator.Reddot) {
  23. res = s.cache
  24. if res != nil {
  25. current := now.Unix()
  26. if current > int64(res.EndTime) || current < int64(res.StartTime) {
  27. res = &operator.Reddot{}
  28. }
  29. }
  30. return
  31. }
  32. func (s *Service) loadCache(c *conf.Config) {
  33. tmp := &operator.Reddot{}
  34. tmp.ReddotChange(c.Reddot.StartTime, c.Reddot.EndTime)
  35. s.cache = tmp
  36. }