[hw-2] add tests, coverage, benchmarks

This commit is contained in:
Никита Шубин
2025-05-31 10:47:47 +00:00
parent 1a3d4892a8
commit a0e36639ca
22 changed files with 3058 additions and 48 deletions

View File

@@ -52,7 +52,7 @@ func NewApp(configPath string) (*App, error) {
app := &App{
config: c,
}
app.server.Handler = app.bootstrapHandlers()
app.server.Handler = app.BootstrapHandlers(app.setupCartService())
return app, nil
}
@@ -70,7 +70,7 @@ func (app *App) ListenAndServe() error {
return app.server.Serve(l)
}
func (app *App) bootstrapHandlers() http.Handler {
func (app *App) setupCartService() *service.CartService {
transport := http.DefaultTransport
transport = round_trippers.NewLogRoundTripper(transport)
transport = round_trippers.NewRetryRoundTripper(transport, productsRetryAttemptsDefault, productsInitialDelaySecDefault)
@@ -88,8 +88,11 @@ func (app *App) bootstrapHandlers() http.Handler {
const userCartCap = 100
cartRepository := repository.NewInMemoryRepository(userCartCap)
cartService := service.NewCartService(cartRepository, productService)
return service.NewCartService(cartRepository, productService)
}
func (app *App) BootstrapHandlers(cartService *service.CartService) http.Handler {
s := server.NewServer(cartService)
mx := http.NewServeMux()