From 71c39ed9f8ce3563130cdfc5099e9d7df60845a9 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 5 Aug 2026 14:17:59 +0200 Subject: refactor: Replace env config with atomic YAML --- main.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 072941f..36b3d28 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "strings" "time" + "github.com/martinlehoux/biking_home/config" "github.com/martinlehoux/biking_home/mountain_pass" "github.com/martinlehoux/biking_home/osmpass" "github.com/martinlehoux/biking_home/ride" @@ -29,12 +30,15 @@ var ( demo = flag.Bool("demo", false, "run the climb similarity demo") chartFile = flag.String("chart", "", "render a climb/pass chart for a GPX file") cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") + configFile = flag.String("config", "config.yaml", "path to the YAML configuration file") parser = ride.GPXRideParser{} ) func main() { flag.Parse() - db, err := sql.Open("sqlite3", "biking_home.db") + appConfig, err := config.Load(*configFile) + kcore.Expect(err, "failed to load configuration") + db, err := sql.Open("sqlite3", appConfig.Database.Path) kcore.Expect(err, "failed to open database") defer db.Close() switch { @@ -58,14 +62,14 @@ func main() { case *chartFile != "": runChart(db, *chartFile) default: - runServer(db) + runServer(db, *configFile, appConfig) } } -func runServer(db *sql.DB) { - server := web.NewServer(db, ".env", "rides", "http://localhost:8080") - slog.Info("Starting web server", "address", "http://localhost:8080") - kcore.Expect(server.ListenAndServe(":8080"), "web server stopped") +func runServer(db *sql.DB, configPath string, appConfig config.Config) { + server := web.NewServer(db, configPath) + slog.Info("Starting web server", "address", appConfig.Server.PublicURL) + kcore.Expect(server.ListenAndServe(appConfig.Server.Address), "web server stopped") } func runChart(db *sql.DB, filename string) { -- cgit v1.2.3