package dao import ( "github.com/go-kratos/kratos/v2/log" "github.com/google/wire" "gorm.io/gorm" "hilo/app/service/demo/internal/conf" "hilo/common/mysql" "hilo/common/redis" ) // ProviderSet is dao providers. var ProviderSet = wire.NewSet(NewDao) // Dao . type Dao struct { DB *gorm.DB Redis *redis.WrapClient } // NewDao . func NewDao(c *conf.Data) (*Dao, func(), error) { db := mysql.NewDB(c.Mysql) rs := redis.NewRedis(c.Redis) cleanup := func() { d, _ := db.DB() d.Close() rs.Client.Close() log.Debug("close data resources") } return &Dao{ DB: db, Redis: rs, }, cleanup, nil }