You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
744 B
43 lines
744 B
package dao |
|
|
|
import ( |
|
"context" |
|
|
|
"go-common/app/service/live/grpc-demo/conf" |
|
"go-common/library/cache/memcache" |
|
"go-common/library/cache/redis" |
|
xsql "go-common/library/database/sql" |
|
) |
|
|
|
// Dao dao |
|
type Dao struct { |
|
c *conf.Config |
|
mc *memcache.Pool |
|
redis *redis.Pool |
|
db *xsql.DB |
|
} |
|
|
|
// New init mysql db |
|
func New(c *conf.Config) (dao *Dao) { |
|
dao = &Dao{ |
|
c: c, |
|
mc: memcache.NewPool(c.Memcache), |
|
redis: redis.NewPool(c.Redis), |
|
db: xsql.NewMySQL(c.MySQL), |
|
} |
|
return |
|
} |
|
|
|
// Close close the resource. |
|
func (d *Dao) Close() { |
|
d.mc.Close() |
|
d.redis.Close() |
|
d.db.Close() |
|
return |
|
} |
|
|
|
// Ping dao ping |
|
func (d *Dao) Ping(c context.Context) error { |
|
// TODO: if you need use mc,redis, please add |
|
return d.db.Ping(c) |
|
}
|
|
|