- Go module + chi server with embedded SPA serving and /api/health - internal/config env loader (local-dev defaults; auth/copyleaks deferred) - React 19 + Vite 6 + Tailwind v4 frontend with full Petal design tokens - Frontend embedded into the binary via web/embed.go (go:embed all:dist) - README dev workflow, .env.example, BUILD_PLAN progress tracker - Verified end-to-end: binary serves health, embedded SPA, and SPA fallback
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// Config holds all runtime configuration, loaded from environment variables.
|
|
// See .env.example for the full list and defaults.
|
|
type Config struct {
|
|
Port string
|
|
BaseURL string
|
|
DatabasePath string
|
|
|
|
// LLM
|
|
LLMBackend string // "vllm" | "ollama"
|
|
LLMEndpoint string
|
|
LLMModel string // checkpoint model (small, fast)
|
|
LLMChatModel string // Ask Petal model; falls back to LLMModel if empty
|
|
LLMTimeout time.Duration
|
|
|
|
// Auth (deferred — not wired in the local-dev build, kept for later)
|
|
AuthentikURL string
|
|
AuthentikClientID string
|
|
AuthentikClientSecret string
|
|
SessionSecret string
|
|
}
|
|
|
|
// Load reads configuration from the environment, applying sane local-dev defaults.
|
|
func Load() *Config {
|
|
return &Config{
|
|
Port: env("PORT", "8080"),
|
|
BaseURL: env("BASE_URL", "http://localhost:8080"),
|
|
DatabasePath: env("DATABASE_PATH", "./data/petal.db"),
|
|
|
|
LLMBackend: env("LLM_BACKEND", "vllm"),
|
|
LLMEndpoint: env("LLM_ENDPOINT", "http://localhost:8000"),
|
|
LLMModel: env("LLM_MODEL", ""),
|
|
LLMChatModel: env("LLM_CHAT_MODEL", ""),
|
|
LLMTimeout: envDuration("LLM_TIMEOUT", 30*time.Second),
|
|
|
|
AuthentikURL: env("AUTHENTIK_URL", ""),
|
|
AuthentikClientID: env("AUTHENTIK_CLIENT_ID", ""),
|
|
AuthentikClientSecret: env("AUTHENTIK_CLIENT_SECRET", ""),
|
|
SessionSecret: env("SESSION_SECRET", "dev-insecure-secret-change-me"),
|
|
}
|
|
}
|
|
|
|
func env(key, fallback string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func envDuration(key string, fallback time.Duration) time.Duration {
|
|
if v := os.Getenv(key); v != "" {
|
|
if d, err := time.ParseDuration(v); err == nil {
|
|
return d
|
|
}
|
|
}
|
|
return fallback
|
|
}
|