rework to lighten the main, refactor wrappers. Rehandle csrf and pull config items.

This commit is contained in:
2025-04-15 22:19:55 +01:00
parent 0a5d61ea1e
commit 0a21973237
7 changed files with 142 additions and 11 deletions

View File

@@ -4,10 +4,15 @@ import (
"database/sql"
"log"
"synlotto-website/config"
"synlotto-website/logging"
_ "modernc.org/sqlite"
)
func InitDB(filepath string) *sql.DB {
var err error
cfg := config.Get()
db, err := sql.Open("sqlite", filepath)
if err != nil {
log.Fatal("❌ Failed to open DB:", err)
@@ -30,6 +35,10 @@ func InitDB(filepath string) *sql.DB {
SchemaSyndicateInvites,
SchemaSyndicateInviteTokens,
}
if cfg == nil {
logging.Error("❌ config is nil — did config.Init() run before InitDB?")
panic("config not ready")
}
for _, stmt := range schemas {
if _, err := db.Exec(stmt); err != nil {