go-common/app/job/main/passport-encrypt/dao/dao.go
2019-04-22 18:49:16 +08:00

49 lines
880 B
Go

package dao
import (
"context"
"go-common/app/job/main/passport-encrypt/conf"
"go-common/library/database/sql"
"go-common/library/log"
)
// Dao dao
type Dao struct {
c *conf.Config
originDB *sql.DB
encryptDB *sql.DB
}
// New new dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
originDB: sql.NewMySQL(c.DB.OriginDB),
encryptDB: sql.NewMySQL(c.DB.EncryptDB),
}
return
}
// Ping check dao ok.
func (d *Dao) Ping(c context.Context) (err error) {
if err = d.originDB.Ping(c); err != nil {
log.Info("dao.originDB.Ping() error(%v)", err)
}
if err = d.encryptDB.Ping(c); err != nil {
log.Info("dao.encryptDB.Ping() error(%v)", err)
}
return
}
// Close close connections of mc, cloudDB.
func (d *Dao) Close() (err error) {
if d.originDB != nil {
d.originDB.Close()
}
if d.encryptDB != nil {
d.encryptDB.Close()
}
return
}