dao.go 594 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package manager
  2. import (
  3. "context"
  4. "github.com/jinzhu/gorm"
  5. "go-common/app/admin/main/videoup/conf"
  6. "go-common/library/database/orm"
  7. )
  8. // Dao is redis dao.
  9. type Dao struct {
  10. c *conf.Config
  11. // db
  12. OverseaDB *gorm.DB
  13. }
  14. var (
  15. d *Dao
  16. )
  17. // New new a dao.
  18. func New(c *conf.Config) (d *Dao) {
  19. d = &Dao{
  20. c: c,
  21. OverseaDB: orm.NewMySQL(c.DB.Oversea),
  22. }
  23. return d
  24. }
  25. // Close close.
  26. func (d *Dao) Close() {
  27. if d.OverseaDB != nil {
  28. d.OverseaDB.Close()
  29. }
  30. }
  31. // Ping ping cpdb
  32. func (d *Dao) Ping(c context.Context) (err error) {
  33. err = d.OverseaDB.DB().PingContext(c)
  34. return
  35. }