af9dc82c58
modified: begushiybashkir/bbvue/src/stores/auth.js modified: serv_nginx/api_bb/.env modified: serv_nginx/api_bb/internal/config/config.go modified: serv_nginx/api_bb/internal/models/user.go modified: serv_nginx/api_bb/internal/routes/routes.go modified: serv_nginx/nginx/nginx-ssl.conf some for get photo from api_bb
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
// config/config.go
|
|
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
DatabaseURL string
|
|
JWTSecret string
|
|
StaticURL string `env:"STATIC_URL" envDefault:"http://localhost:8080"`
|
|
}
|
|
|
|
func Load() *Config {
|
|
_ = godotenv.Load(".env")
|
|
port := getEnv("PORT", "8080")
|
|
jwtSecret := getEnv("JWT_SECRET", "your-secret-key")
|
|
|
|
// Формируем DSN для PostgreSQL из переменных окружения
|
|
databaseURL := getPostgresDSN()
|
|
|
|
return &Config{
|
|
Port: port,
|
|
DatabaseURL: databaseURL,
|
|
JWTSecret: jwtSecret,
|
|
}
|
|
}
|
|
|
|
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 == "" {
|
|
return defaultValue
|
|
}
|
|
return value
|
|
}
|