package config import ( "fmt" "strings" ) // sampleEntry is one line pair in the sample env file: a comment and the // (usually commented-out) KEY=VALUE line. type sampleEntry struct { name string value string comment string active bool // rendered uncommented } // SampleEnv renders a sample .env file covering every setting, each with a // comment line. Everything is commented out — so all defaults apply — // except LOG_FILE when logFile is non-empty: a Windows service has no // console, so the installer pre-wires file logging there. func SampleEnv(logFile string) string { entries := []sampleEntry{ {"LISTEN_OLLAMA", ":11434", "Ollama-facing listener address", false}, {"LISTEN_COMFY", ":8188", "ComfyUI-facing listener address", false}, {"OLLAMA_URL", "http://127.0.0.1:11434", "Ollama upstream URL; setting it enables the Ollama consumer (default: empty = disabled)", false}, {"COMFY_URL", "http://127.0.0.1:8188", "ComfyUI upstream URL; setting it enables the ComfyUI consumer (default: empty = disabled)", false}, {"WARM_MODEL", "", "Optional model to reload after an image job (default: empty = none)", false}, {"UNLOAD_TIMEOUT", "60s", "How long to wait for Ollama to unload a model", false}, {"JOB_TIMEOUT", "15m", "Maximum time to wait for a ComfyUI job", false}, {"LLM_WAIT_TIMEOUT", "10m", "Max time an LLM request waits for the GPU before being answered 503 (wait mode)", false}, {"LLM_BUSY_MODE", "wait", `How blocked LLM requests are handled: "wait" holds them, "reject" fails them immediately`, false}, {"LLM_BUSY_STATUS", "503", "HTTP status for rejected LLM requests in reject mode (400-599, e.g. 429)", false}, {"BUSY_RETRY_AFTER", "30", "Seconds sent as Retry-After on busy responses (both modes)", false}, {"LOGLEVEL", "warn", `Log verbosity: debug, info, warn, error; "info" logs every request (LOG_LEVEL works too)`, false}, {"LOG_FORMAT", "text", `Log format: "text" or "json"`, false}, {"LOG_FILE", logFile, "Append logs to this file instead of stderr (a Windows service has no console)", logFile != ""}, {"UNLOAD_POLL_INTERVAL", "500ms", "/api/ps poll interval while unloading", false}, {"HISTORY_POLL_INTERVAL", "1s", "/history/ poll interval while a job runs", false}, {"PROBE_TIMEOUT", "5s", "Startup probe timeout for the enabled upstreams", false}, {"FREE_TIMEOUT", "30s", "Timeout for the POST /free call after an image job", false}, {"WARM_TIMEOUT", "2m", "Timeout for the warm-model reload after an image job", false}, {"SHUTDOWN_TIMEOUT", "10s", "Graceful shutdown timeout on SIGINT/SIGTERM", false}, {"BACKOFF_INITIAL", "1s", "First retry wait when an upstream connection fails", false}, {"BACKOFF_MAX", "60s", "Cap for the exponential retry backoff", false}, {"PROMPT_CAPTURE_LIMIT", "65536", "Bytes of the /prompt response buffered to find prompt_id (pass-through unaffected)", false}, {"AUTO_UPDATE", "true", "Poll the releases API for signed updates", false}, {"UPDATE_INTERVAL", "6h", "Auto-update check interval", false}, {"UPDATE_REPO", "https://git.rambossek.at/PUBLIC/gpu-turnstile", "Repository to check for releases", false}, {"UPDATE_ASSET", "gpu-turnstile.exe", "Release asset to download", false}, } var b strings.Builder b.WriteString("# gpu-turnstile configuration\n") b.WriteString("# KEY=VALUE lines; \"#\" starts a comment. Every setting below is at its\n") b.WriteString("# default and commented out — remove the \"#\" to change it.\n") b.WriteString("# At least one of OLLAMA_URL / COMFY_URL must be set for the proxy to start.\n\n") for _, e := range entries { fmt.Fprintf(&b, "# %s\n", e.comment) if e.active { fmt.Fprintf(&b, "%s=%s\n\n", e.name, e.value) } else { fmt.Fprintf(&b, "#%s=%s\n\n", e.name, e.value) } } return b.String() }