dao.go 976 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "time"
  4. "go-common/app/admin/main/answer/conf"
  5. "go-common/library/cache/redis"
  6. "go-common/library/database/elastic"
  7. "go-common/library/database/orm"
  8. "github.com/jinzhu/gorm"
  9. )
  10. // Dao struct info of Dao.
  11. type Dao struct {
  12. c *conf.Config
  13. db *gorm.DB
  14. es *elastic.Elastic
  15. redis *redis.Pool
  16. redisExpire int32
  17. }
  18. // TextImgConf text img conf.
  19. type TextImgConf struct {
  20. Fontsize int
  21. Length int
  22. Ansfontsize int
  23. Spacing float64
  24. Ansspacing float64
  25. }
  26. // New new a Dao and return.
  27. func New(c *conf.Config) (d *Dao) {
  28. d = &Dao{
  29. c: c,
  30. db: orm.NewMySQL(c.Mysql),
  31. es: elastic.NewElastic(nil),
  32. redis: redis.NewPool(c.Redis.Config),
  33. redisExpire: int32(time.Duration(c.Redis.Expire) / time.Second),
  34. }
  35. return
  36. }
  37. // Close close connections of mc, redis, db.
  38. func (d *Dao) Close() {
  39. if d.db != nil {
  40. d.db.Close()
  41. }
  42. if d.redis != nil {
  43. d.redis.Close()
  44. }
  45. }