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
+2 -2
View File
@@ -8,7 +8,7 @@ OPENAI_MODEL=deepseek-v4-pro
DB_MODE=sqlite
#DB_MODE=pgs
DB_PATH=./data/app.db
LOG_LEVEL=warn
LOG_LEVEL=info
STREAMING=true
DB_TIMEZONE=Europe/Istanbul
+3
View File
@@ -17,6 +17,7 @@ type Config struct {
RequestTimeoutSeconds int
OpenAIModel string // default model when client omits it
Streaming bool // enable/disable SSE streaming responses
DBTimezone string // PostgreSQL session timezone (e.g. "Europe/Istanbul")
}
// Load reads environment variables and returns a populated Config.
@@ -51,6 +52,7 @@ func Load() *Config {
openAIApiKey := os.Getenv("OPENAI_KEY")
openAIModel := os.Getenv("OPENAI_MODEL")
dbTimezone := os.Getenv("DB_TIMEZONE")
streaming := true
if v := os.Getenv("STREAMING"); v != "" {
@@ -70,5 +72,6 @@ func Load() *Config {
RequestTimeoutSeconds: timeoutSec,
OpenAIModel: openAIModel,
Streaming: streaming,
DBTimezone: dbTimezone,
}
}
BIN
View File
Binary file not shown.
+1
View File
@@ -20,6 +20,7 @@
| `REQUEST_TIMEOUT_SECONDS` | `30` | `RequestTimeoutSeconds` | Upstream istek zaman aşımı (saniye) |
| `OPENAI_MODEL` | `""` | `OpenAIModel` | Varsayılan model adı (istekte model yoksa enjekte edilir) |
| `STREAMING` | `true` | `Streaming` | SSE streaming yanıtlarını etkinleştir/devre dışı bırak (`true`/`false`) |
| `DB_TIMEZONE` | `""` | `DBTimezone` | PostgreSQL oturum zaman dilimi (örn: `Europe/Istanbul`) |
## Önemli Detaylar
+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()
}