dao.go 634 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package operation
  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. // Close Dao
  24. func (dao *Dao) Close() {
  25. dao.db.Close()
  26. }
  27. // Ping Dao
  28. func (dao *Dao) Ping(c context.Context) error {
  29. return dao.db.Ping(c)
  30. }