Files
panelhosting/internal/config/config.go
T

59 lines
1.1 KiB
Go

package config
import (
"fmt"
"os"
)
type Config struct {
DatabaseURL string
HTTPPort string
DefaultServerName string
DefaultServerHost string
DefaultServerIP string
SessionCookieName string
SessionTTLHours int
}
func Load() (*Config, error) {
url := os.Getenv("DATABASE_URL")
if url == "" {
return nil, fmt.Errorf("DATABASE_URL is required")
}
port := os.Getenv("HTTP_PORT")
if port == "" {
port = "8000"
}
serverName := os.Getenv("DEFAULT_SERVER_NAME")
if serverName == "" {
serverName = "local"
}
serverHost := os.Getenv("DEFAULT_SERVER_HOSTNAME")
if serverHost == "" {
serverHost = "localhost"
}
serverIP := os.Getenv("DEFAULT_SERVER_IP")
if serverIP == "" {
serverIP = "127.0.0.1"
}
cookieName := os.Getenv("SESSION_COOKIE_NAME")
if cookieName == "" {
cookieName = "panel_session"
}
return &Config{
DatabaseURL: url,
HTTPPort: port,
DefaultServerName: serverName,
DefaultServerHost: serverHost,
DefaultServerIP: serverIP,
SessionCookieName: cookieName,
SessionTTLHours: 168, // 7 days
}, nil
}