Re-work loading of configuration, introduce a loader for start up & and custom logging wrapper.
This commit is contained in:
14
main.go
14
main.go
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user