fix: restructure env handling for better testing capabillities #181
All checks were successful
Build Docker Image / Explore-Gitea-Actions (push) Successful in 47s
Build and Push Docker Image / Explore-Gitea-Actions (push) Successful in 55s

This commit was merged in pull request #195.
This commit is contained in:
2024-09-29 23:51:23 +02:00
parent 25e82be339
commit a70138f2f7
15 changed files with 191 additions and 152 deletions

View File

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