service.go 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/live/open-interface/internal/dao"
  5. titansSdk "go-common/app/service/live/resource/sdk"
  6. "go-common/library/conf/paladin"
  7. )
  8. // Service service.
  9. type Service struct {
  10. ac *paladin.Map
  11. dao *dao.Dao
  12. }
  13. // New new a service and return.
  14. func New() (s *Service) {
  15. var ac = new(paladin.TOML)
  16. if err := paladin.Watch("application.toml", ac); err != nil {
  17. panic(err)
  18. }
  19. s = &Service{
  20. ac: ac,
  21. dao: dao.New(),
  22. }
  23. dao.InitGrpc()
  24. InitTitan()
  25. return s
  26. }
  27. //InitTitan 初始化kv配置
  28. func InitTitan() {
  29. conf := &titansSdk.Config{
  30. TreeId: 82686,
  31. Expire: 1,
  32. }
  33. titansSdk.Init(conf)
  34. }
  35. // Ping ping the resource.
  36. func (s *Service) Ping(ctx context.Context) (err error) {
  37. return s.dao.Ping(ctx)
  38. }
  39. // Close close the resource.
  40. func (s *Service) Close() {
  41. s.dao.Close()
  42. }