2024-08-05 09:11:43 +00:00
|
|
|
package svc
|
|
|
|
|
2024-08-06 05:59:24 +00:00
|
|
|
import (
|
|
|
|
"ark-permission/internal/config"
|
|
|
|
"ark-permission/internal/domain/repository"
|
|
|
|
"ark-permission/internal/lib/required"
|
|
|
|
repo "ark-permission/internal/repository"
|
2024-08-08 03:02:13 +00:00
|
|
|
ers "code.30cm.net/wanderland/library-go/errors"
|
|
|
|
"code.30cm.net/wanderland/library-go/errors/code"
|
2024-08-06 05:59:24 +00:00
|
|
|
"github.com/zeromicro/go-zero/core/stores/redis"
|
|
|
|
)
|
2024-08-05 09:11:43 +00:00
|
|
|
|
|
|
|
type ServiceContext struct {
|
|
|
|
Config config.Config
|
2024-08-06 05:59:24 +00:00
|
|
|
|
|
|
|
Validate required.Validate
|
|
|
|
Redis redis.Redis
|
|
|
|
TokenRedisRepo repository.TokenRepository
|
2024-08-05 09:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
2024-08-06 05:59:24 +00:00
|
|
|
newRedis, err := redis.NewRedis(c.RedisCluster, redis.Cluster())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-08-08 03:02:13 +00:00
|
|
|
ers.Scope = code.CloudEPPermission
|
2024-08-06 05:59:24 +00:00
|
|
|
|
2024-08-05 09:11:43 +00:00
|
|
|
return &ServiceContext{
|
2024-08-06 05:59:24 +00:00
|
|
|
Config: c,
|
|
|
|
Validate: required.MustValidator(),
|
|
|
|
Redis: *newRedis,
|
|
|
|
TokenRedisRepo: repo.NewTokenRepository(repo.TokenRepositoryParam{
|
|
|
|
Store: newRedis,
|
|
|
|
}),
|
2024-08-05 09:11:43 +00:00
|
|
|
}
|
|
|
|
}
|