service.go 784 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package region
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "encoding/json"
  6. "time"
  7. "go-common/app/interface/main/app-feed/conf"
  8. tagdao "go-common/app/interface/main/app-feed/dao/tag"
  9. "go-common/library/log"
  10. )
  11. type Service struct {
  12. c *conf.Config
  13. // dao
  14. tg *tagdao.Dao
  15. // tick
  16. tick time.Duration
  17. // infoc
  18. logCh chan interface{}
  19. }
  20. // New a region service.
  21. func New(c *conf.Config) (s *Service) {
  22. s = &Service{
  23. c: c,
  24. tg: tagdao.New(c),
  25. tick: time.Duration(c.Tick),
  26. // infoc
  27. logCh: make(chan interface{}, 1024),
  28. }
  29. go s.infocproc()
  30. return
  31. }
  32. func (s *Service) md5(v interface{}) string {
  33. bs, err := json.Marshal(v)
  34. if err != nil {
  35. log.Error("json.Marshal error(%v)", err)
  36. return "region_version"
  37. }
  38. hs := md5.Sum(bs)
  39. return hex.EncodeToString(hs[:])
  40. }