This commit is contained in:
@@ -2,6 +2,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -33,7 +34,6 @@ func Load() (Config, error) {
|
|||||||
mode := os.Getenv("RUN_MODE")
|
mode := os.Getenv("RUN_MODE")
|
||||||
debugMode := os.Getenv("DEBUG_MODE") == "true"
|
debugMode := os.Getenv("DEBUG_MODE") == "true"
|
||||||
botToken := os.Getenv("BOT_TOKEN")
|
botToken := os.Getenv("BOT_TOKEN")
|
||||||
dbConnectionString := os.Getenv("DB_PATH")
|
|
||||||
ocrTokenPath := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
ocrTokenPath := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||||
apiPort := os.Getenv("API_PORT")
|
apiPort := os.Getenv("API_PORT")
|
||||||
apiHost := os.Getenv("API_HOST")
|
apiHost := os.Getenv("API_HOST")
|
||||||
@@ -42,6 +42,7 @@ func Load() (Config, error) {
|
|||||||
openAPIEndpoint := os.Getenv("OPEN_API_ENDPOINT")
|
openAPIEndpoint := os.Getenv("OPEN_API_ENDPOINT")
|
||||||
|
|
||||||
runMode, err := ParseRunMode(mode)
|
runMode, err := ParseRunMode(mode)
|
||||||
|
dbConnectionString := buildConnectionString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
warnings = append(warnings, err.Error())
|
warnings = append(warnings, err.Error())
|
||||||
}
|
}
|
||||||
@@ -61,9 +62,6 @@ func Load() (Config, error) {
|
|||||||
if apiSecret == "" {
|
if apiSecret == "" {
|
||||||
warnings = append(warnings, "Missing required environment variable: API_SECRET")
|
warnings = append(warnings, "Missing required environment variable: API_SECRET")
|
||||||
}
|
}
|
||||||
if dbConnectionString == "" {
|
|
||||||
dbConnectionString = "sqlite://data/app.db"
|
|
||||||
}
|
|
||||||
if apiHost == "" {
|
if apiHost == "" {
|
||||||
apiHost = "localhost"
|
apiHost = "localhost"
|
||||||
}
|
}
|
||||||
@@ -92,3 +90,30 @@ func Load() (Config, error) {
|
|||||||
TelegramApi: "https://api.telegram.org",
|
TelegramApi: "https://api.telegram.org",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildConnectionString() string {
|
||||||
|
// если задана готовая строка — используем её (удобно для локальной разработки через .env)
|
||||||
|
if dsn := os.Getenv("DB_PATH"); dsn != "" {
|
||||||
|
return dsn
|
||||||
|
}
|
||||||
|
|
||||||
|
// собираем из отдельных переменных (для Kubernetes)
|
||||||
|
host := os.Getenv("DB_HOST")
|
||||||
|
port := os.Getenv("DB_PORT")
|
||||||
|
user := os.Getenv("DB_USER")
|
||||||
|
password := os.Getenv("DB_PASSWORD")
|
||||||
|
dbName := os.Getenv("DB_NAME")
|
||||||
|
|
||||||
|
if host == "" || user == "" || password == "" || dbName == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if port == "" {
|
||||||
|
port = "5432"
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf(
|
||||||
|
"postgres://%s:%s@%s:%s/%s?sslmode=disable",
|
||||||
|
user, password, host, port, dbName,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user