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.
50 lines
807 B
50 lines
807 B
package dao |
|
|
|
import ( |
|
"context" |
|
|
|
"go-common/library/cache/redis" |
|
"go-common/library/conf/paladin" |
|
"go-common/library/queue/databus" |
|
) |
|
|
|
// Dao dao. |
|
type Dao struct { |
|
redis *redis.Pool |
|
pushBus *databus.Databus |
|
} |
|
|
|
func checkErr(err error) { |
|
if err != nil { |
|
panic(err) |
|
} |
|
} |
|
|
|
// New new a dao and return. |
|
func New() (dao *Dao) { |
|
var ( |
|
rds struct { |
|
Push *redis.Config |
|
} |
|
dbus struct { |
|
Push *databus.Config |
|
} |
|
) |
|
checkErr(paladin.Get("redis.toml").UnmarshalTOML(&rds)) |
|
checkErr(paladin.Get("databus.toml").UnmarshalTOML(&dbus)) |
|
dao = &Dao{ |
|
redis: redis.NewPool(rds.Push), |
|
pushBus: databus.New(dbus.Push), |
|
} |
|
return |
|
} |
|
|
|
// Close close the resource. |
|
func (d *Dao) Close() { |
|
d.redis.Close() |
|
} |
|
|
|
// Ping dao ping. |
|
func (d *Dao) Ping(c context.Context) error { |
|
return d.pingRedis(c) |
|
}
|
|
|