service.go 872 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package service
  2. import (
  3. "sync"
  4. "go-common/app/admin/main/config/conf"
  5. "go-common/app/admin/main/config/dao"
  6. confrpc "go-common/app/infra/config/rpc/client"
  7. "go-common/app/admin/main/config/model"
  8. "github.com/jinzhu/gorm"
  9. )
  10. // Service service
  11. type Service struct {
  12. c *conf.Config
  13. // rpcconf config service Rpc
  14. confSvr *confrpc.Service2
  15. dao *dao.Dao
  16. cLock sync.RWMutex
  17. cache map[string]*model.CacheData
  18. //apm gorm
  19. DBApm *gorm.DB
  20. //db gorm
  21. DB *gorm.DB
  22. }
  23. // New new a service
  24. func New(c *conf.Config) (s *Service) {
  25. s = &Service{
  26. c: c,
  27. confSvr: confrpc.New2(c.ConfSvr),
  28. dao: dao.New(c),
  29. }
  30. s.cache = make(map[string]*model.CacheData)
  31. s.DBApm = s.dao.DBApm
  32. s.DB = s.dao.DB
  33. return
  34. }
  35. // Ping check server ok.
  36. func (s *Service) Ping() (err error) {
  37. return
  38. }
  39. // Close close resource
  40. func (s *Service) Close() {
  41. s.dao.Close()
  42. }