app-cloudep-permission-server/internal/svc/service_context.go

43 lines
1.0 KiB
Go

package svc
import (
"app-cloudep-permission-server/internal/config"
"app-cloudep-permission-server/internal/domain/repository"
repo "app-cloudep-permission-server/internal/repository"
ers "code.30cm.net/digimon/library-go/errors"
"code.30cm.net/digimon/library-go/errors/code"
vi "code.30cm.net/digimon/library-go/validator"
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
type ServiceContext struct {
Config config.Config
Conn sqlx.SqlConn
Validate vi.Validate
Redis redis.Redis
TokenRedisRepo repository.TokenRepository
}
func NewServiceContext(c config.Config) *ServiceContext {
ers.Scope = code.CloudEPPermission
sqlConn := sqlx.NewMysql(c.DB.DsnString)
newRedis, err := redis.NewRedis(c.RedisCluster, redis.Cluster())
if err != nil {
panic(err)
}
return &ServiceContext{
Conn: sqlConn,
Config: c,
Validate: vi.MustValidator(),
Redis: *newRedis,
TokenRedisRepo: repo.NewTokenRepository(repo.TokenRepositoryParam{
Store: newRedis,
}),
}
}