package backend import ( "encoding/json" "fmt" "os" "path/filepath" ) type ModelConfig struct { Key string `json:"key"` Model string `json:"model"` In float64 `json:"in"` Out float64 `json:"out"` } func (a *App) GetModelConfig() *ModelConfig { content, err := os.ReadFile(filepath.Join("./config", "model.json")) if err != nil { return &ModelConfig{} } resp := &ModelConfig{} if err = json.Unmarshal(content, &resp); err != nil { return &ModelConfig{} } return resp } func (a *App) SetModelConfig(req *ModelConfig) { data, err := json.Marshal(req) if err != nil { fmt.Printf("保存模型配置失败: %v\n", err) return } // 写入配置文件 configPath := filepath.Join("./config", "model.json") if err := os.WriteFile(configPath, data, 0644); err != nil { fmt.Printf("保存模型配置失败: %v\n", err) return } }