dao.go 807 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dao
  2. import (
  3. "context"
  4. "go-common/library/cache/redis"
  5. "go-common/library/conf/paladin"
  6. "go-common/library/queue/databus"
  7. )
  8. // Dao dao.
  9. type Dao struct {
  10. redis *redis.Pool
  11. pushBus *databus.Databus
  12. }
  13. func checkErr(err error) {
  14. if err != nil {
  15. panic(err)
  16. }
  17. }
  18. // New new a dao and return.
  19. func New() (dao *Dao) {
  20. var (
  21. rds struct {
  22. Push *redis.Config
  23. }
  24. dbus struct {
  25. Push *databus.Config
  26. }
  27. )
  28. checkErr(paladin.Get("redis.toml").UnmarshalTOML(&rds))
  29. checkErr(paladin.Get("databus.toml").UnmarshalTOML(&dbus))
  30. dao = &Dao{
  31. redis: redis.NewPool(rds.Push),
  32. pushBus: databus.New(dbus.Push),
  33. }
  34. return
  35. }
  36. // Close close the resource.
  37. func (d *Dao) Close() {
  38. d.redis.Close()
  39. }
  40. // Ping dao ping.
  41. func (d *Dao) Ping(c context.Context) error {
  42. return d.pingRedis(c)
  43. }