From bddcfc6778237aad4e1e016ec6c1804c638e1b03 Mon Sep 17 00:00:00 2001 From: Tim Wundenberg Date: Fri, 27 Sep 2024 23:21:37 +0200 Subject: [PATCH] chore: parametrize db path #181 --- handler/auth_test.go | 11 +++++++++++ main.go | 2 +- types/settings.go | 7 +++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 handler/auth_test.go diff --git a/handler/auth_test.go b/handler/auth_test.go new file mode 100644 index 0000000..921902a --- /dev/null +++ b/handler/auth_test.go @@ -0,0 +1,11 @@ +package handler + +import ( + "testing" +) + +func TestHandleSignIn(t *testing.T) { + t.Parallel() + t.Run("should signIn and return session cookie", func(t *testing.T) { + }) +} 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{