wannpassts/backend/internal/config/config.go
Tronax cb30223fd4
feat: add WannPassts booking app with Go backend and Vue frontend
Initial project setup for a privacy-focused, self-hosted scheduling app:

- Go backend with JWT auth, SQLite storage, and chi router
- Calendar integrations via Google OAuth (FreeBusy), CalDAV, and ICS links
- Public booking pages with configurable slots and booking requests
- AES-256-GCM encryption for stored provider tokens
- Vue 3 + TypeScript frontend with Vite, Pinia, and Vue Router
- Docs, .gitignore, and .env.example for local development
2026-08-25 18:50:28 +02:00

64 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"crypto/rand"
"encoding/hex"
"log"
"os"
"github.com/joho/godotenv"
)
type Config struct {
Port string
DBPath string
AppURL string
FrontendURL string
JWTSecret string
EncryptionKey string
GoogleClientID string
GoogleClientSecret string
StaticDir string
}
// Load liest die Konfiguration aus Umgebungsvariablen (.env wird unterstützt).
// Fehlende Secrets werden nur für die Entwicklung zufällig erzeugt.
func Load() Config {
_ = godotenv.Load()
cfg := Config{
Port: env("PORT", "8080"),
DBPath: env("DB_PATH", "wannpassts.db"),
AppURL: env("APP_URL", "http://localhost:8080"),
FrontendURL: env("FRONTEND_URL", "http://localhost:5173"),
JWTSecret: os.Getenv("JWT_SECRET"),
EncryptionKey: os.Getenv("ENCRYPTION_KEY"),
GoogleClientID: os.Getenv("GOOGLE_CLIENT_ID"),
GoogleClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"),
StaticDir: env("STATIC_DIR", ""),
}
if cfg.JWTSecret == "" {
cfg.JWTSecret = randomHex(32)
log.Println("WARNUNG: JWT_SECRET nicht gesetzt temporäres Secret erzeugt (Sessions verfallen bei Neustart).")
}
if cfg.EncryptionKey == "" {
cfg.EncryptionKey = randomHex(32)
log.Println("WARNUNG: ENCRYPTION_KEY nicht gesetzt temporärer Schlüssel erzeugt (Kalender-Tokens verfallen bei Neustart).")
}
return cfg
}
func env(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}
func randomHex(n int) string {
b := make([]byte, n)
if _, err := rand.Read(b); err != nil {
log.Fatalf("Zufallszahl nicht verfügbar: %v", err)
}
return hex.EncodeToString(b)
}