announcemgr.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package announce
  2. import (
  3. "encoding/json"
  4. "sync"
  5. "bet24.com/servers/common"
  6. "bet24.com/log"
  7. )
  8. type announceMgr struct {
  9. list []*info
  10. lock *sync.RWMutex
  11. }
  12. func newAnnounceMgr() *announceMgr {
  13. obj := new(announceMgr)
  14. obj.lock = &sync.RWMutex{}
  15. obj.load()
  16. log.Debug("announce manager running")
  17. return obj
  18. }
  19. func (this *announceMgr) load() {
  20. list := getList()
  21. this.lock.Lock()
  22. defer this.lock.Unlock()
  23. this.list = list
  24. }
  25. func (this *announceMgr) getJson() string {
  26. var list []*info
  27. now := common.GetNowTime()
  28. this.lock.RLock()
  29. defer this.lock.RUnlock()
  30. for _, v := range this.list {
  31. if v.Enabled != 1 {
  32. continue
  33. }
  34. begin := common.ParseTime(v.BeginTime)
  35. // log.Debug("announce.getJson v=%+v now=%v begin=%v", v, now, begin)
  36. if now.Before(begin) {
  37. continue
  38. }
  39. end := common.ParseTime(v.EndTime)
  40. // log.Debug("announce.getJson v=%+v now=%v end=%v", v, now, end)
  41. if now.After(end) {
  42. continue
  43. }
  44. // log.Debug("announce.getJson v=%+v ", v, now, end)
  45. list = append(list, v)
  46. }
  47. d, _ := json.Marshal(list)
  48. return string(d)
  49. }