dao.go 756 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package archive
  2. import (
  3. "time"
  4. "go-common/app/service/main/up/conf"
  5. "go-common/library/cache/redis"
  6. "go-common/library/database/sql"
  7. "go-common/library/stat/prom"
  8. )
  9. // Dao is archive dao.
  10. type Dao struct {
  11. c *conf.Config
  12. resultDB *sql.DB
  13. archiveDB *sql.DB
  14. // redis
  15. upRds *redis.Pool
  16. upExpire int32
  17. errProm *prom.Prom
  18. infoProm *prom.Prom
  19. }
  20. // New new a Dao and return.
  21. func New(c *conf.Config) (d *Dao) {
  22. d = &Dao{
  23. c: c,
  24. // db
  25. resultDB: sql.NewMySQL(c.DB.ArcResult),
  26. archiveDB: sql.NewMySQL(c.DB.Archive),
  27. // redis
  28. upRds: redis.NewPool(c.Redis.Up.Config),
  29. upExpire: int32(time.Duration(c.Redis.Up.UpExpire) / time.Second),
  30. errProm: prom.BusinessErrCount,
  31. infoProm: prom.BusinessInfoCount,
  32. }
  33. return
  34. }