Initial scaffold: Go backend, React frontend, Docker Compose
- Go backend: config, db (PostgreSQL migrations), auth (argon2id + sessions), middleware (cookie sessions, RequireAuth), chi router, cmd/server - React frontend: Vite + React 18 + TS + Tailwind + Gruvbox palette + terminal CSS - Docker: compose.yml (Postgres, Valkey, minio, LiveKit, coturn, Caddy), livekit.yaml, Caddyfile, Dockerfile (multi-stage Go+Node+Alpine) - .env.example, .gitignore, README.md
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Host string
|
||||
Port string
|
||||
Database DatabaseConfig
|
||||
Valkey ValkeyConfig
|
||||
Session SessionConfig
|
||||
}
|
||||
|
||||
type DatabaseConfig struct {
|
||||
Host string
|
||||
Port string
|
||||
User string
|
||||
Password string
|
||||
Database string
|
||||
}
|
||||
|
||||
type ValkeyConfig struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
type SessionConfig struct {
|
||||
CookieName string
|
||||
Duration time.Duration
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
return &Config{
|
||||
Host: getEnv("DUMPSTER_HOST", "localhost"),
|
||||
Port: getEnv("DUMPSTER_PORT", "8080"),
|
||||
Database: DatabaseConfig{
|
||||
Host: getEnv("POSTGRES_HOST", "localhost"),
|
||||
Port: getEnv("POSTGRES_PORT", "5432"),
|
||||
User: getEnv("POSTGRES_USER", "dumpster"),
|
||||
Password: getEnv("POSTGRES_PASSWORD", "dumpster"),
|
||||
Database: getEnv("POSTGRES_DB", "dumpster"),
|
||||
},
|
||||
Valkey: ValkeyConfig{
|
||||
URL: getEnv("VALKEY_URL", "redis://localhost:***@example.com"),
|
||||
},
|
||||
Session: SessionConfig{
|
||||
CookieName: getEnv("DUMPSTER_SESSION_COOKIE", "dumpster_session"),
|
||||
Duration: time.Duration(getInt("DUMPSTER_SESSION_DAYS", 30)) * 24 * time.Hour,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) DatabaseDSN() string {
|
||||
return "postgres://" + c.Database.User + ":***@" + c.Database.Host + ":" + c.Database.Port + "/" + c.Database.Database + "?sslmode=disable"
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return strings.TrimSpace(v)
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
|
||||
func getBool(key string, fallback bool) bool {
|
||||
s := strings.ToLower(getEnv(key, ""))
|
||||
if s == "" {
|
||||
return fallback
|
||||
}
|
||||
return s == "true" || s == "1" || s == "yes"
|
||||
}
|
||||
|
||||
func getInt(key string, fallback int) int {
|
||||
s := getEnv(key, "")
|
||||
if s == "" {
|
||||
return fallback
|
||||
}
|
||||
n, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
return n
|
||||
}
|
||||
Reference in New Issue
Block a user