guard/internal/svc/service_context.go

37 lines
893 B
Go
Raw Normal View History

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"
)
type ServiceContext struct {
Config config.Config
2024-08-06 05:59:24 +00:00
Validate required.Validate
Redis redis.Redis
TokenRedisRepo repository.TokenRepository
}
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
return &ServiceContext{
2024-08-06 05:59:24 +00:00
Config: c,
Validate: required.MustValidator(),
Redis: *newRedis,
TokenRedisRepo: repo.NewTokenRepository(repo.TokenRepositoryParam{
Store: newRedis,
}),
}
}