dao.go 628 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package job
  2. import (
  3. "context"
  4. "go-common/app/interface/main/web-show/conf"
  5. xsql "go-common/library/database/sql"
  6. "go-common/library/log"
  7. "go-common/library/stat/prom"
  8. )
  9. // Dao struct
  10. type Dao struct {
  11. db *xsql.DB
  12. }
  13. // PromError err
  14. func PromError(name string, format string, args ...interface{}) {
  15. prom.BusinessErrCount.Incr(name)
  16. log.Error(format, args...)
  17. }
  18. // New conf
  19. func New(c *conf.Config) (dao *Dao) {
  20. dao = &Dao{db: xsql.NewMySQL(c.MySQL.Operation)}
  21. return
  22. }
  23. // Ping Dao
  24. func (dao *Dao) Ping(c context.Context) error {
  25. return dao.db.Ping(c)
  26. }
  27. // Close Dao
  28. func (dao *Dao) Close() {
  29. dao.db.Close()
  30. }