partnerlist.go 787 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package serverdata
  2. import (
  3. "sync"
  4. "time"
  5. "bet24.com/servers/adminserver/dao"
  6. )
  7. type PartnerList struct {
  8. partners []dao.PartnerInfo
  9. lock *sync.RWMutex
  10. }
  11. func NewPartnerList() *PartnerList {
  12. obj := new(PartnerList)
  13. obj.lock = &sync.RWMutex{}
  14. return obj
  15. }
  16. func (this *PartnerList) GetPartners() []dao.PartnerInfo {
  17. this.lock.RLock()
  18. defer this.lock.RUnlock()
  19. return this.partners
  20. }
  21. func (this *PartnerList) run() {
  22. this.refreshData()
  23. }
  24. func (this *PartnerList) refreshData() {
  25. go this.doRefresh()
  26. time.AfterFunc(5*time.Minute, this.refreshData)
  27. }
  28. func (this *PartnerList) doRefresh() {
  29. obj := dao.NewPartnerList()
  30. obj.DoAction(nil)
  31. this.lock.Lock()
  32. this.partners = obj.Out.List
  33. this.lock.Unlock()
  34. }
  35. func (this *PartnerList) Refresh() {
  36. this.doRefresh()
  37. }