setting.go 934 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "time"
  6. "go-common/app/job/openplatform/article/dao"
  7. "go-common/app/job/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 = &model.Setting{}
  20. }
  21. for name, value := range settings {
  22. switch name {
  23. case "recheck_view":
  24. var recheckView = &model.Recheck{}
  25. if err = json.Unmarshal([]byte(value), recheckView); err != nil {
  26. log.Error("setting.Unmarshal(%s) error(%+v)", value, err)
  27. dao.PromError("service:配置项无效")
  28. } else {
  29. s.setting.Recheck = recheckView
  30. }
  31. }
  32. }
  33. return
  34. }
  35. }
  36. func (s *Service) loadSettingsproc() {
  37. for {
  38. time.Sleep(time.Minute)
  39. s.loadSettings()
  40. }
  41. }