This repository has been archived on 2025-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
web-app-template/handler/default.go
Tim Wundenberg bc24d5a705
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Has been cancelled
fix: create RandomGenerator interface and struct for testing purpose #181
2024-10-05 13:51:36 +02:00

36 lines
946 B
Go

package handler
import (
"me-fit/db"
"me-fit/middleware"
"me-fit/service"
"me-fit/types"
"database/sql"
"net/http"
)
func GetHandler(d *sql.DB, serverSettings *types.ServerSettings) http.Handler {
var router = http.NewServeMux()
router.HandleFunc("/", service.HandleIndexAnd404(d, serverSettings))
randomGenerator := service.NewRandomGeneratorImpl()
dbAuth := db.NewDbAuthSqlite(d)
serviceAuth := service.NewServiceAuthImpl(dbAuth, randomGenerator, serverSettings)
handlerAuth := NewHandlerAuth(d, serviceAuth, serverSettings)
// Serve static files (CSS, JS and images)
router.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))
handleWorkout(d, router, serverSettings)
handlerAuth.handle(router)
return middleware.Logging(middleware.EnableCors(serverSettings, router))
}
func authMiddleware(db *sql.DB, h http.Handler) http.Handler {
return middleware.EnsureValidSession(db, h)
}