first
This commit is contained in:
30
app/user/cmd/api/internal/svc/servicecontext.go
Normal file
30
app/user/cmd/api/internal/svc/servicecontext.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"qnc-server/app/user/cmd/api/internal/config"
|
||||
"qnc-server/app/user/model"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Redis *redis.Redis
|
||||
UserModel model.UserModel
|
||||
UserAuthModel model.UserAuthModel
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
db := sqlx.NewMysql(c.DataSource) // 创建数据库连接
|
||||
redisConf := redis.RedisConf{
|
||||
Host: c.CacheRedis[0].Host,
|
||||
Pass: c.CacheRedis[0].Pass,
|
||||
Type: c.CacheRedis[0].Type, // Redis 节点类型,如 "node"
|
||||
}
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Redis: redis.MustNewRedis(redisConf),
|
||||
UserModel: model.NewUserModel(db, c.CacheRedis),
|
||||
UserAuthModel: model.NewUserAuthModel(db, c.CacheRedis),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user