dao.go 484 B

123456789101112131415161718192021222324252627282930313233
  1. package show
  2. import (
  3. "context"
  4. "go-common/app/service/main/resource/conf"
  5. xsql "go-common/library/database/sql"
  6. )
  7. // Dao is resource dao.
  8. type Dao struct {
  9. db *xsql.DB
  10. c *conf.Config
  11. }
  12. // New init mysql db
  13. func New(c *conf.Config) (d *Dao) {
  14. d = &Dao{
  15. c: c,
  16. db: xsql.NewMySQL(c.DB.Show),
  17. }
  18. return
  19. }
  20. // Close close the resource.
  21. func (d *Dao) Close() {
  22. d.db.Close()
  23. }
  24. // Ping check dao health.
  25. func (d *Dao) Ping(c context.Context) error {
  26. return d.db.Ping(c)
  27. }