Phase 0: skeleton, config, chi router, /healthz

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jānis Kacēns
2026-05-11 11:25:00 +03:00
commit 34eb47b595
9 changed files with 645 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
package config
import (
"os"
"strings"
)
type Config struct {
OpenAIAPIKey string
SessionSecret string
DataDir string
Port string
AdminUsers []AdminUser
}
type AdminUser struct {
Name string
Password string
}
func Load() *Config {
cfg := &Config{
OpenAIAPIKey: os.Getenv("OPENAI_API_KEY"),
SessionSecret: os.Getenv("SESSION_SECRET"),
DataDir: envOr("DATA_DIR", "./data"),
Port: envOr("PORT", "8080"),
}
cfg.AdminUsers = parseAdminUsers(os.Getenv("ADMIN_USERS"))
return cfg
}
func envOr(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}
func parseAdminUsers(raw string) []AdminUser {
if raw == "" {
return nil
}
var users []AdminUser
for _, pair := range strings.Split(raw, ",") {
pair = strings.TrimSpace(pair)
name, pass, ok := strings.Cut(pair, ":")
if !ok || name == "" || pass == "" {
continue
}
users = append(users, AdminUser{Name: name, Password: pass})
}
return users
}