modified: serv_nginx/api_bb/cmd/main.go
modified: serv_nginx/api_bb/go.mod modified: serv_nginx/api_bb/go.sum modified: serv_nginx/api_bb/internal/config/config.go modified: serv_nginx/api_bb/pkg/database/database.go change database to postgresql form sqlite
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package config
|
||||
|
||||
import "os"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port string
|
||||
@@ -9,7 +12,9 @@ type Config struct {
|
||||
|
||||
func Load() *Config {
|
||||
port := getEnv("PORT", "8080")
|
||||
databaseURL := getEnv("DATABASE_URL", "sqlite:test.db")
|
||||
|
||||
// Формируем DSN для PostgreSQL из переменных окружения
|
||||
databaseURL := getPostgresDSN()
|
||||
|
||||
return &Config{
|
||||
Port: port,
|
||||
@@ -17,6 +22,18 @@ func Load() *Config {
|
||||
}
|
||||
}
|
||||
|
||||
func getPostgresDSN() string {
|
||||
host := getEnv("DB_HOST", "localhost")
|
||||
port := getEnv("DB_PORT", "5432")
|
||||
user := getEnv("DB_USER", "postgres")
|
||||
password := getEnv("DB_PASSWORD", "postgres")
|
||||
dbname := getEnv("DB_NAME", "bb_db")
|
||||
sslmode := getEnv("DB_SSLMODE", "disable")
|
||||
|
||||
return fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s",
|
||||
host, port, user, password, dbname, sslmode)
|
||||
}
|
||||
|
||||
func getEnv(key, defaultValue string) string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
|
||||
Reference in New Issue
Block a user