package svc import ( "app-cloudep-trade-service/internal/config" duc "app-cloudep-trade-service/internal/domain/usecase" "app-cloudep-trade-service/internal/usecase" "github.com/zeromicro/go-zero/core/stores/sqlx" ers "code.30cm.net/digimon/library-go/errs" "code.30cm.net/digimon/library-go/errs/code" vi "code.30cm.net/digimon/library-go/validator" ) type ServiceContext struct { Config config.Config Validate vi.Validate OrderUseCase duc.OrderUseCase SQLConn sqlx.SqlConn } func NewServiceContext(c config.Config) *ServiceContext { // TODO 改成 Trade ers.Scope = code.CloudEPOrder om := MustOrderModel(c) orderUseCase := usecase.NewOrderUseCase(usecase.OrderUseCaseParam{ OrderModel: om, }) mysql, err := newDatabase(c) if err != nil { panic("failed to connect to wallet") } // 創建 SQL 連線並返回 sqlConn := sqlx.NewSqlConnFromDB(mysql) return &ServiceContext{ Config: c, Validate: vi.MustValidator( WithDecimalGt(), WithDecimalGte(), ), SQLConn: sqlConn, OrderUseCase: orderUseCase, } }