package rank import ( "sync" "time" item "bet24.com/servers/micros/item_inventory/proto" ) var Awards *AwardList type AwardList struct { Awards []RankAwardInfo lock *sync.RWMutex } func NewAwardList() *AwardList { obj := new(AwardList) obj.lock = &sync.RWMutex{} return obj } func (al *AwardList) Run() { al.refreshData() } func (al *AwardList) refreshData() { go al.doRefresh() time.AfterFunc(3*time.Second, al.refreshData) } func (al *AwardList) doRefresh() { list := getAwardList() al.lock.Lock() defer al.lock.Unlock() al.Awards = list } // 根据排名获取奖励信息 func (al *AwardList) getAwards(rankType, rank int) []item.ItemPack { al.lock.RLock() list := al.Awards al.lock.RUnlock() for _, v := range list { if v.RankType != rankType || v.Rank != rank { continue } return v.Items } return nil } // 获取奖励列表 func (al *AwardList) getList() []RankAwardInfo { al.lock.RLock() defer al.lock.RUnlock() return al.Awards }