gift.go 683 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package gift
  2. import (
  3. giftservice "bet24.com/servers/micros/giftservice/proto"
  4. "time"
  5. )
  6. var mgr *giftManager
  7. type giftManager struct {
  8. gift_list []giftservice.Gift
  9. }
  10. func getGiftManager() *giftManager {
  11. if mgr == nil {
  12. mgr = new(giftManager)
  13. mgr.refreshData()
  14. }
  15. return mgr
  16. }
  17. func (this *giftManager) refreshData() {
  18. this.load()
  19. time.AfterFunc(1*time.Minute, this.refreshData)
  20. }
  21. func (this *giftManager) load() {
  22. list := giftservice.GetGiftList(0)
  23. if len(list) == 0 {
  24. return
  25. }
  26. this.gift_list = list
  27. }
  28. func (this *giftManager) getGiftName(giftId int) string {
  29. for _, v := range this.gift_list {
  30. if v.GiftId == giftId {
  31. return v.Desc
  32. }
  33. }
  34. return ""
  35. }