Re-work loading of configuration, introduce a loader for start up & and custom logging wrapper.

This commit is contained in:
2025-04-15 21:10:57 +01:00
parent d7c15141b8
commit 0a5d61ea1e
6 changed files with 119 additions and 3 deletions

14
main.go
View File

@@ -3,8 +3,11 @@ package main
import (
"log"
"net/http"
"synlotto-website/bootstrap"
"synlotto-website/config"
"synlotto-website/handlers"
"synlotto-website/helpers"
"synlotto-website/logging"
"synlotto-website/middleware"
"synlotto-website/models"
"synlotto-website/routes"
@@ -14,11 +17,16 @@ import (
)
func main() {
appState, err := bootstrap.LoadAppState("config/config.json")
if err != nil {
logging.Error("Failed to load app state: %v", err)
}
config.Init(appState.Config)
logging.LogConfig(appState.Config)
db := storage.InitDB("synlotto.db")
models.SetDB(db) // Should be in storage not models.
var isProduction = false
csrfMiddleware := csrf.Protect(
[]byte("abcdefghijklmnopqrstuvwx12345678"), // TodO: Make Global
csrf.Secure(true),
@@ -35,7 +43,7 @@ func main() {
mux.HandleFunc("/", handlers.Home(db))
wrapped := helpers.RateLimit(csrfMiddleware(mux))
wrapped = middleware.EnforceHTTPS(wrapped, isProduction)
wrapped = middleware.EnforceHTTPS(wrapped, appState.Config.HttpServer.ProductionMode)
wrapped = middleware.SecureHeaders(wrapped)
wrapped = middleware.Recover(wrapped)