feat: add DB_TIMEZONE configuration and update logging for PostgreSQL timezone

This commit is contained in:
Beyhan Ogur
2026-05-11 17:08:48 +03:00
parent c56ae7194c
commit aa6dbfefb3
5 changed files with 30 additions and 3 deletions
+24 -1
View File
@@ -22,6 +22,7 @@ package main
import (
"fmt"
"log"
"net/url"
"os"
"path/filepath"
@@ -67,7 +68,11 @@ func main() {
dialector = sqlite.Open(dsn)
dbEngine = "sqlite"
default:
dialector = postgres.Open(cfg.PostgresDSN)
dsn := cfg.PostgresDSN
if cfg.DBTimezone != "" {
dsn = appendQueryParam(dsn, "timezone", cfg.DBTimezone)
}
dialector = postgres.Open(dsn)
}
var err error
@@ -161,9 +166,27 @@ func main() {
log.Printf(" DB logging : enabled")
}
log.Printf(" SSE streaming : %v", cfg.Streaming)
if cfg.DBTimezone != "" {
log.Printf(" DB timezone : %s", cfg.DBTimezone)
}
if err := app.Listen(addr); err != nil {
log.Fatalf("server error: %v", err)
os.Exit(1)
}
}
func appendQueryParam(dsn, key, value string) string {
if value == "" {
return dsn
}
u, err := url.Parse(dsn)
if err != nil {
log.Printf("⚠️ Failed to parse DSN for timezone: %v", err)
return dsn
}
q := u.Query()
q.Set(key, value)
u.RawQuery = q.Encode()
return u.String()
}