diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-05 14:17:59 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-05 14:17:59 +0200 |
| commit | 71c39ed9f8ce3563130cdfc5099e9d7df60845a9 (patch) | |
| tree | e610b8360f6364e3ab7c5e817ac94bd51cc0dfd1 /main.go | |
| parent | bef31e1d35fe88f2698cf0e3191f26a79623f66f (diff) | |
refactor: Replace env config with atomic YAML
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -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) { |