From 763104a91682b77e88bf0115c04a9c32c862db81 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Tue, 1 Oct 2024 22:44:24 +0200 Subject: [PATCH] chore: parametrize db path --- main.go | 2 +- types/settings.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 44087fc..dfdfe4c 100644 --- a/main.go +++ b/main.go @@ -40,7 +40,7 @@ func run(ctx context.Context, env func(string) string) { serverSettings := types.NewServerSettingsFromEnv(env) // init db - db, err := sql.Open("sqlite3", "./data.db") + db, err := sql.Open("sqlite3", serverSettings.DbPath) if err != nil { log.Fatal("Could not open Database data.db: ", err) } diff --git a/types/settings.go b/types/settings.go index 25556c4..d41ad0e 100644 --- a/types/settings.go +++ b/types/settings.go @@ -8,6 +8,7 @@ import ( type ServerSettings struct { BaseUrl string Environment string + DbPath string Smtp *SmtpSettings } @@ -21,6 +22,12 @@ type SmtpSettings struct { } func NewServerSettingsFromEnv(env func(string) string) *ServerSettings { + + dbPath := env("DB_PATH") + if dbPath == "" { + dbPath = "./data.db" + } + var smtp *SmtpSettings if env("SMTP_ENABLED") == "true" { smtp = &SmtpSettings{