Интернет-магазин: Go, PostgreSQL 17 SSL, Caddy, Docker Compose

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
shop
2026-05-16 17:09:27 +03:00
commit 448cf2a465
21 changed files with 1208 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
package config
import (
"fmt"
"os"
"strconv"
"time"
)
type Config struct {
HTTPAddr string
DatabaseURL string
ReadTimeout time.Duration
WriteTimeout time.Duration
}
func Load() (Config, error) {
port := env("APP_PORT", "8080")
cfg := Config{
HTTPAddr: ":" + port,
DatabaseURL: os.Getenv("DATABASE_URL"),
ReadTimeout: durationEnv("HTTP_READ_TIMEOUT", 10*time.Second),
WriteTimeout: durationEnv("HTTP_WRITE_TIMEOUT", 30*time.Second),
}
if cfg.DatabaseURL == "" {
return cfg, fmt.Errorf("DATABASE_URL is required")
}
return cfg, nil
}
func env(key, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}
func durationEnv(key string, fallback time.Duration) time.Duration {
v := os.Getenv(key)
if v == "" {
return fallback
}
sec, err := strconv.Atoi(v)
if err != nil || sec <= 0 {
return fallback
}
return time.Duration(sec) * time.Second
}