dao.go 657 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package dao
  2. import (
  3. "go-common/app/admin/main/appstatic/conf"
  4. "go-common/library/cache/redis"
  5. "go-common/library/database/orm"
  6. httpx "go-common/library/net/http/blademaster"
  7. "github.com/jinzhu/gorm"
  8. )
  9. // Dao .
  10. type Dao struct {
  11. DB *gorm.DB
  12. c *conf.Config
  13. client *httpx.Client
  14. redis *redis.Pool
  15. }
  16. // New new a instance
  17. func New(c *conf.Config) (d *Dao) {
  18. d = &Dao{
  19. // db
  20. DB: orm.NewMySQL(c.ORM),
  21. c: c,
  22. client: httpx.NewClient(c.HTTPClient),
  23. redis: redis.NewPool(c.Redis.Config),
  24. }
  25. d.DB.LogMode(true)
  26. return
  27. }
  28. // Close close connection of db , mc.
  29. func (d *Dao) Close() {
  30. if d.DB != nil {
  31. d.DB.Close()
  32. }
  33. }