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

30
bootstrap/loader.go Normal file
View File

@@ -0,0 +1,30 @@
package bootstrap
import (
"encoding/json"
"fmt"
"os"
"synlotto-website/models"
)
type AppState struct {
Config *models.Config
}
func LoadAppState(configPath string) (*AppState, error) {
file, err := os.Open(configPath)
if err != nil {
return nil, fmt.Errorf("open config: %w", err)
}
defer file.Close()
var config models.Config
if err := json.NewDecoder(file).Decode(&config); err != nil {
return nil, fmt.Errorf("decode config: %w", err)
}
return &AppState{
Config: &config,
}, nil
}