dao.go 583 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/seq-server/conf"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. // Dao is seq-server dao.
  9. type Dao struct {
  10. c *conf.Config
  11. // db
  12. db *sql.DB
  13. }
  14. // New new a Dao and return.
  15. func New(c *conf.Config) (d *Dao) {
  16. d = &Dao{
  17. c: c,
  18. // db
  19. db: sql.NewMySQL(c.DB.Number),
  20. }
  21. return
  22. }
  23. // Ping ping db
  24. func (d *Dao) Ping() (err error) {
  25. if err = d.db.Ping(context.TODO()); err != nil {
  26. log.Error("d.db.Ping error(%v)", err)
  27. }
  28. return
  29. }
  30. // Close close resource.
  31. func (d *Dao) Close() {
  32. d.db.Close()
  33. }