Documentation
¶
Index ¶
- Constants
- func CloseCron()
- func CloseDB(t *testing.T, db *gorm.DB)
- func CronLogger() cron.Logger
- func GetDsn(engine, host, port, user, password, dbname string) string
- func GetEtcdClient() *clientv3.Client
- func GetTransaction(c context.Context) *gorm.DB
- func InitCron()
- func NewDB(params NewDbParams) *gorm.DB
- func NewEtcdClient(endpoints []string) *clientv3.Client
- func NewRedisClient(host string, port int, user string, password string, db int) *redis.Client
- func NewTestDB(t *testing.T, params TestDBParams) *gorm.DB
- func NewTestRedis(t *testing.T, params TestRedisParams) cache.Cache
- func SetTransaction(c context.Context, tran *gorm.DB) context.Context
- func StopTaskQueue()
- func TaskQueue() *task.TaskQueue
- type CustomCronLogger
- type Data
- type NatsMQ
- type NewDbParams
- type RedisClient
- type TestDBParams
- type TestRedisParams
Constants ¶
View Source
const ( EngineMysql = "mysql" EnginePostgres = "postgres" )
Variables ¶
This section is empty.
Functions ¶
func CronLogger ¶
func GetEtcdClient ¶
func NewDB ¶
func NewDB( params NewDbParams, ) *gorm.DB
func NewEtcdClient ¶
func NewRedisClient ¶
func NewTestDB ¶
func NewTestDB(t *testing.T, params TestDBParams) *gorm.DB
NewTestDB 创建测试用 MySQL 数据库连接 所有微服务的 data 层测试统一引用此函数,避免重复创建连接的代码。
用法:
func TestXxx(t *testing.T) {
db := infra.NewTestDB(t, infra.TestDBParams{
Driver: "mysql",
Host: "127.0.0.1",
Port: 3306,
User: "root",
Password: "password",
DBName: "vcyuan",
})
defer func() {
sqlDB, _ := db.DB()
sqlDB.Close()
}()
repo := NewXxxRepo(&data.Data{DB: db})
// ...
}
func NewTestRedis ¶
func NewTestRedis(t *testing.T, params TestRedisParams) cache.Cache
NewTestRedis 创建测试用 Redis 缓存实例 所有微服务的 data 层测试统一引用此函数。
用法:
func TestXxx(t *testing.T) {
cache := infra.NewTestRedis(t, infra.TestRedisParams{
Host: "127.0.0.1",
Port: 6379,
})
defer cache.Close()
repo := NewXxxRepo(&data.Data{Cache: cache})
// ...
}
func StopTaskQueue ¶
func StopTaskQueue()
Types ¶
type CustomCronLogger ¶
type CustomCronLogger struct {
// contains filtered or unexported fields
}
func (*CustomCronLogger) Error ¶
func (cl *CustomCronLogger) Error(err error, msg string, keysAndValues ...interface{})
func (*CustomCronLogger) Info ¶
func (cl *CustomCronLogger) Info(msg string, keysAndValues ...interface{})
type Data ¶
type NewDbParams ¶
type RedisClient ¶
func NewCustomRedisClient ¶
func NewCustomRedisClient(rdb *redis.Client) *RedisClient
Click to show internal directories.
Click to hide internal directories.