dao.go 873 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/admin/main/laser/conf"
  5. "go-common/library/cache/memcache"
  6. "go-common/library/database/sql"
  7. bm "go-common/library/net/http/blademaster"
  8. "time"
  9. )
  10. // Dao struct.
  11. type Dao struct {
  12. c *conf.Config
  13. laserDB *sql.DB
  14. mc *memcache.Pool
  15. mcExpire int32
  16. HTTPClient *bm.Client
  17. }
  18. // New Dao instance.
  19. func New(c *conf.Config) (d *Dao) {
  20. d = &Dao{
  21. c: c,
  22. laserDB: sql.NewMySQL(c.Mysql),
  23. mc: memcache.NewPool(c.Memcache.Laser.Config),
  24. mcExpire: int32(time.Duration(c.Memcache.Laser.Expire) / time.Second),
  25. HTTPClient: bm.NewClient(c.HTTPClient),
  26. }
  27. return
  28. }
  29. // Ping check db connection.
  30. func (d *Dao) Ping(c context.Context) (err error) {
  31. return d.laserDB.Ping(c)
  32. }
  33. // Close dao resources.
  34. func (d *Dao) Close(c context.Context) (err error) {
  35. return d.laserDB.Close()
  36. }