setting.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package service
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/app/interface/openplatform/article/dao"
  7. artmdl "go-common/app/interface/openplatform/article/model"
  8. "go-common/library/log"
  9. )
  10. func (s *Service) loadSettings() {
  11. for {
  12. settings, err := s.dao.Settings(context.TODO())
  13. if err != nil || len(settings) == 0 {
  14. dao.PromError("service:获取配置")
  15. time.Sleep(time.Second)
  16. continue
  17. }
  18. if s.setting == nil {
  19. s.setting = &artmdl.Setting{}
  20. }
  21. for name, value := range settings {
  22. switch name {
  23. case "apply_open":
  24. var open bool
  25. if open, err = strconv.ParseBool(value); err != nil {
  26. dao.PromError("service:配置项无效")
  27. log.Error("strconv.ParseBool(%v: %v) err: %+v", name, value, err)
  28. } else {
  29. s.setting.ApplyOpen = open
  30. }
  31. case "apply_limit":
  32. var limit int64
  33. if limit, err = strconv.ParseInt(value, 10, 64); err != nil {
  34. dao.PromError("service:配置项无效")
  35. log.Error("strconv.ParseInt(%v:%v) err: %+v", name, value, err)
  36. } else {
  37. s.setting.ApplyLimit = limit
  38. }
  39. case "frozen_duration":
  40. var duration int64
  41. if duration, err = strconv.ParseInt(value, 10, 64); err != nil {
  42. dao.PromError("service:配置项无效")
  43. log.Error("strconv.ParseInt(%v:%v) err: %+v", name, value, err)
  44. } else {
  45. s.setting.ApplyFrozenDuration = duration
  46. }
  47. case "show_rec_new_arts":
  48. var show bool
  49. if show, err = strconv.ParseBool(value); err != nil {
  50. dao.PromError("service:配置项无效")
  51. log.Error("strconv.ParseBool(%v: %v) err: %+v", name, value, err)
  52. } else {
  53. s.setting.ShowRecommendNewArticles = show
  54. }
  55. case "show_rank_note":
  56. var show bool
  57. if show, err = strconv.ParseBool(value); err != nil {
  58. dao.PromError("service:配置项无效")
  59. log.Error("strconv.ParseBool(%v: %v) err: %+v", name, value, err)
  60. } else {
  61. s.setting.ShowRankNote = show
  62. }
  63. case "show_app_home_rank":
  64. var show bool
  65. if show, err = strconv.ParseBool(value); err != nil {
  66. dao.PromError("service:配置项无效")
  67. log.Error("strconv.ParseBool(%v: %v) err: %+v", name, value, err)
  68. } else {
  69. s.setting.ShowAppHomeRank = show
  70. }
  71. case "show_later_watch":
  72. var show bool
  73. if show, err = strconv.ParseBool(value); err != nil {
  74. dao.PromError("service:配置项无效")
  75. log.Error("strconv.ParseBool(%v: %v) err: %+v", name, value, err)
  76. } else {
  77. s.setting.ShowLaterWatch = show
  78. }
  79. case "show_small_window":
  80. var show bool
  81. if show, err = strconv.ParseBool(value); err != nil {
  82. dao.PromError("service:配置项无效")
  83. log.Error("strconv.ParseBool(%v: %v) err: %+v", name, value, err)
  84. } else {
  85. s.setting.ShowSmallWindow = show
  86. }
  87. case "hotspot":
  88. var show bool
  89. if show, err = strconv.ParseBool(value); err != nil {
  90. dao.PromError("service:配置项无效")
  91. log.Error("strconv.ParseBool(%v: %v) err: %+v", name, value, err)
  92. } else {
  93. s.setting.ShowHotspot = show
  94. }
  95. }
  96. }
  97. return
  98. }
  99. }
  100. func (s *Service) loadSettingsproc() {
  101. for {
  102. time.Sleep(time.Minute)
  103. s.loadSettings()
  104. }
  105. }