service.go 667 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package service
  2. import (
  3. "context"
  4. "sync"
  5. "go-common/app/admin/main/sms/conf"
  6. "go-common/app/admin/main/sms/dao"
  7. "github.com/jinzhu/gorm"
  8. )
  9. // Service is service.
  10. type Service struct {
  11. c *conf.Config
  12. dao *dao.Dao
  13. wg sync.WaitGroup
  14. db *gorm.DB
  15. closed bool
  16. }
  17. // New is workflow-admin service implementation.
  18. func New(c *conf.Config) (s *Service) {
  19. s = &Service{
  20. c: c,
  21. dao: dao.New(c),
  22. }
  23. s.db = s.dao.DB
  24. return s
  25. }
  26. // Ping check server ok.
  27. func (s *Service) Ping(c context.Context) (err error) {
  28. err = s.dao.Ping(c)
  29. return
  30. }
  31. // Close consumer close.
  32. func (s *Service) Close() {
  33. s.closed = true
  34. s.dao.Close()
  35. s.wg.Wait()
  36. }