package svc import ( "member/internal/config" "member/internal/domain" "member/internal/lib/required" "member/internal/model" "github.com/zeromicro/go-zero/core/stores/redis" ers "member/internal/lib/error" "github.com/zeromicro/go-zero/core/stores/sqlx" ) type ServiceContext struct { Config config.Config Redis redis.Redis Validate required.Validate AccountModel model.AccountModel UserModel model.UserTableModel AccountToUidModel model.AccountToUidModel SnackFlowGen SnackFlow } func NewServiceContext(c config.Config) *ServiceContext { sqlConn := sqlx.NewMysql(c.DB.DsnString) // 設置 ers.Scope = domain.Scope n, err := NewSnackFlow(model.NewMachineNodeModel(sqlConn, c.Cache)) if err != nil { panic(err) } newRedis, err := redis.NewRedis(c.RedisCluster, redis.Cluster()) if err != nil { panic(err) } return &ServiceContext{ Config: c, Redis: *newRedis, Validate: required.MustValidator(required.WithAccount("account")), UserModel: model.NewUserTableModel(sqlConn, c.Cache), AccountToUidModel: model.NewAccountToUidModel(sqlConn, c.Cache), AccountModel: model.NewAccountModel(sqlConn, c.Cache), SnackFlowGen: n, } }