blockchain/internal/svc/service_context.go

45 lines
980 B
Go
Raw Normal View History

2025-08-04 01:55:56 +00:00
package svc
2025-08-04 14:02:01 +00:00
import (
"blockchain/internal/config"
"blockchain/internal/domain/repository"
"blockchain/internal/domain/usecase"
repo "blockchain/internal/repository"
uc "blockchain/internal/usecase"
"github.com/zeromicro/go-zero/core/stores/redis"
)
2025-08-04 01:55:56 +00:00
type ServiceContext struct {
2025-08-04 14:02:01 +00:00
Config config.Config
BinanceDataSource usecase.DataSourceUseCase
BinanceRepo repository.DataSourceRepository
2025-08-04 01:55:56 +00:00
}
func NewServiceContext(c config.Config) *ServiceContext {
2025-08-04 14:02:01 +00:00
newRedis, err := redis.NewRedis(c.RedisCluster)
if err != nil {
panic(err)
}
2025-08-05 23:41:29 +00:00
cassandra, err := NewDB(c)
if err != nil {
return nil
}
2025-08-06 07:08:32 +00:00
binanceRepo := repo.MustBinanceRepository(repo.BinanceRepositoryParam{
2025-08-06 23:41:18 +00:00
Conf: &c.Binance,
Redis: newRedis,
DB: cassandra,
KeySpace: c.Cassandra.Keyspace,
2025-08-06 07:08:32 +00:00
})
2025-08-04 01:55:56 +00:00
return &ServiceContext{
2025-08-04 14:02:01 +00:00
Config: c,
BinanceRepo: binanceRepo,
BinanceDataSource: uc.MustBinanceUseCase(uc.BinanceUseCaseParam{
BinanceRepo: binanceRepo,
}),
2025-08-04 01:55:56 +00:00
}
}