chore: parametrize db path #181

This commit is contained in:
2024-09-27 23:21:37 +02:00
parent a53ad627fc
commit bddcfc6778
3 changed files with 19 additions and 1 deletions

11
handler/auth_test.go Normal file
View File

@@ -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) {
})
}

View File

@@ -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)
}

View File

@@ -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{