dao.go 861 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package dao
  2. import (
  3. "context"
  4. "crypto/tls"
  5. "go-common/app/job/main/mcn/conf"
  6. "go-common/library/cache/memcache"
  7. xsql "go-common/library/database/sql"
  8. gomail "gopkg.in/gomail.v2"
  9. )
  10. // Dao dao
  11. type Dao struct {
  12. c *conf.Config
  13. mc *memcache.Pool
  14. db *xsql.DB
  15. email *gomail.Dialer
  16. }
  17. // New init mysql db
  18. func New(c *conf.Config) (dao *Dao) {
  19. dao = &Dao{
  20. c: c,
  21. mc: memcache.NewPool(c.Memcache),
  22. db: xsql.NewMySQL(c.MySQL),
  23. // mail
  24. email: gomail.NewDialer(c.MailConf.Host, c.MailConf.Port, c.MailConf.Username, c.MailConf.Password),
  25. }
  26. dao.email.TLSConfig = &tls.Config{
  27. InsecureSkipVerify: true,
  28. }
  29. return
  30. }
  31. // Close close the resource.
  32. func (d *Dao) Close() {
  33. d.mc.Close()
  34. d.db.Close()
  35. }
  36. // Ping dao ping
  37. func (d *Dao) Ping(c context.Context) error {
  38. // TODO: if you need use mc,redis, please add
  39. return d.db.Ping(c)
  40. }