package main import ( "encoding/json" "fmt" "os" ) type APIConfig struct { Key string `json:"key"` Model string `json:"model"` } type Config struct { Port int `json:"port"` Mode string `json:"mode"` ProjectsPath string `json:"projects_path"` Username string `json:"username"` Password string `json:"password"` SessionSecret string `json:"session_secret"` API APIConfig `json:"api"` } func LoadConfig(path string) (*Config, error) { data, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("reading config: %w", err) } var cfg Config if err := json.Unmarshal(data, &cfg); err != nil { return nil, fmt.Errorf("parsing config: %w", err) } if cfg.Port == 0 { cfg.Port = 9100 } if cfg.Mode == "" { cfg.Mode = "cli" } if cfg.ProjectsPath == "" { cfg.ProjectsPath = "/root/projects" } if cfg.Username == "" { return nil, fmt.Errorf("username is required") } if cfg.Password == "" { return nil, fmt.Errorf("password is required") } if cfg.SessionSecret == "" { return nil, fmt.Errorf("session_secret is required") } return &cfg, nil }