service.go 687 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/openplatform/open-market/conf"
  6. "go-common/app/job/openplatform/open-market/dao"
  7. )
  8. // Service struct of service.
  9. type Service struct {
  10. c *conf.Config
  11. dao *dao.Dao
  12. }
  13. // New create service instance and return.
  14. func New(c *conf.Config) (s *Service) {
  15. d := dao.New(c)
  16. s = &Service{
  17. c: c,
  18. dao: d,
  19. }
  20. go s.fetchData()
  21. return
  22. }
  23. // Close close service.
  24. func (s *Service) Close() (err error) {
  25. s.dao.Close()
  26. return
  27. }
  28. // Ping ping service.
  29. func (s *Service) Ping(c context.Context) (err error) {
  30. return s.dao.Ping(c)
  31. }
  32. func (s *Service) fetchData() {
  33. for {
  34. s.marketProc()
  35. time.Sleep(time.Hour * 24)
  36. }
  37. }