chore(deps): remove dependencies from handler package

This commit is contained in:
2024-12-01 21:50:22 +01:00
parent e201ac7b2c
commit 48ec7b64ac
5 changed files with 46 additions and 54 deletions

40
main.go
View File

@@ -1,7 +1,10 @@
package main
import (
"me-fit/db"
"me-fit/handler"
"me-fit/middleware"
"me-fit/service"
"me-fit/types"
"me-fit/utils"
@@ -64,7 +67,7 @@ func run(ctx context.Context, db *sql.DB, env func(string) string) {
httpServer := &http.Server{
Addr: ":" + serverSettings.Port,
Handler: handler.GetHandler(db, serverSettings),
Handler: createHandler(db, serverSettings),
}
go startServer(httpServer)
@@ -99,3 +102,38 @@ func shutdownServer(s *http.Server, ctx context.Context, wg *sync.WaitGroup) {
slog.Info("Gracefully stopped http server on " + s.Addr)
}
}
func createHandler(d *sql.DB, serverSettings *types.ServerSettings) http.Handler {
var router = http.NewServeMux()
authDb := db.NewAuthDbSqlite(d)
workoutDb := db.NewWorkoutDbSqlite(d)
randomService := service.NewRandomServiceImpl()
clockService := service.NewClockServiceImpl()
mailService := service.NewMailServiceImpl(serverSettings)
authService := service.NewAuthServiceImpl(authDb, randomService, clockService, mailService, serverSettings)
workoutService := service.NewWorkoutServiceImpl(workoutDb, randomService, clockService, mailService, serverSettings)
indexHandler := handler.NewIndexHandler(d, authService, serverSettings)
authHandler := handler.NewHandlerAuth(d, authService, serverSettings)
workoutHandler := handler.NewWorkoutHandler(d, workoutService, authService, serverSettings)
indexHandler.Handle(router)
// Serve static files (CSS, JS and images)
router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
workoutHandler.Handle(router)
authHandler.Handle(router)
return middleware.Wrapper(
router,
middleware.Log,
middleware.ContentSecurityPolicy,
middleware.Cors(serverSettings),
middleware.Corp,
middleware.Coop,
)
}