chore: parametrize db path #181
This commit is contained in:
11
handler/auth_test.go
Normal file
11
handler/auth_test.go
Normal 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) {
|
||||
})
|
||||
}
|
||||
2
main.go
2
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)
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user