dao.go 920 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package medal
  2. import (
  3. "go-common/app/job/main/usersuit/conf"
  4. "go-common/app/service/main/usersuit/rpc/client"
  5. "go-common/library/cache/memcache"
  6. "go-common/library/database/sql"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. var (
  10. _updateinfo = "/mingpai/api/updateinfo/%s"
  11. )
  12. // Dao struct info of Dao.
  13. type Dao struct {
  14. db *sql.DB
  15. c *conf.Config
  16. client *bm.Client
  17. suitRPC *client.Service2
  18. updateInfo string
  19. // memcache
  20. mc *memcache.Pool
  21. }
  22. // New new a Dao and return.
  23. func New(c *conf.Config) (d *Dao) {
  24. d = &Dao{
  25. c: c,
  26. db: sql.NewMySQL(c.Mysql),
  27. client: bm.NewClient(c.HTTPClient),
  28. updateInfo: c.Properties.UpInfoURL + _updateinfo,
  29. suitRPC: client.New(c.SuitRPC),
  30. // memcache
  31. mc: memcache.NewPool(c.Memcache.Config),
  32. }
  33. return
  34. }
  35. // Close close connections of mc, redis, db.
  36. func (d *Dao) Close() {
  37. if d.db != nil {
  38. d.db.Close()
  39. }
  40. }