2024-08-24 07:14:58 +00:00
|
|
|
package svc
|
|
|
|
|
2024-08-24 14:40:42 +00:00
|
|
|
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"
|
|
|
|
)
|
2024-08-24 07:14:58 +00:00
|
|
|
|
|
|
|
type ServiceContext struct {
|
|
|
|
Config config.Config
|
2024-08-24 14:40:42 +00:00
|
|
|
Conn sqlx.SqlConn
|
|
|
|
|
|
|
|
Validate vi.Validate
|
|
|
|
Redis redis.Redis
|
|
|
|
TokenRedisRepo repository.TokenRepository
|
2024-08-24 07:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
2024-08-24 14:40:42 +00:00
|
|
|
ers.Scope = code.CloudEPPermission
|
|
|
|
sqlConn := sqlx.NewMysql(c.DB.DsnString)
|
|
|
|
|
|
|
|
newRedis, err := redis.NewRedis(c.RedisCluster, redis.Cluster())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2024-08-24 07:14:58 +00:00
|
|
|
return &ServiceContext{
|
2024-08-24 14:40:42 +00:00
|
|
|
Conn: sqlConn,
|
|
|
|
Config: c,
|
|
|
|
Validate: vi.MustValidator(),
|
|
|
|
Redis: *newRedis,
|
|
|
|
TokenRedisRepo: repo.NewTokenRepository(repo.TokenRepositoryParam{
|
|
|
|
Store: newRedis,
|
|
|
|
}),
|
2024-08-24 07:14:58 +00:00
|
|
|
}
|
|
|
|
}
|