Phase 0: skeleton, config, chi router, /healthz
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user