01ecdc8c23
- Go module with standard library + gorilla/sessions + mysql driver - Config: env-based configuration with .env file support - Database: MySQL connection with auto-migration for 6 tables - Seed data: 12 system tags with options, 8 system snippets - Auth: session cookie middleware - Handlers: auth, tags, snippets, builder, claude, dashboard, suggestions, settings - LLM: OpenAI-compatible client with 30s timeout - Docker: Dockerfile + docker-compose.yml - .env.example with all configuration options Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"prompt-generator/internal/db"
|
|
"prompt-generator/internal/models"
|
|
)
|
|
|
|
func GetSettings(w http.ResponseWriter, r *http.Request) {
|
|
settings := models.Settings{
|
|
LLMAPIBaseURL: cfg.LLMAPIBaseURL,
|
|
LLMModelName: cfg.LLMModelName,
|
|
}
|
|
success(w, settings)
|
|
}
|
|
|
|
func UpdateSettings(w http.ResponseWriter, r *http.Request) {
|
|
var req struct {
|
|
LLMAPIBaseURL string `json:"llm_api_base_url"`
|
|
LLMAPIKey string `json:"llm_api_key"`
|
|
LLMModelName string `json:"llm_model_name"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
fail(w, 400, "请求格式错误")
|
|
return
|
|
}
|
|
|
|
// Update in-memory config
|
|
if req.LLMAPIBaseURL != "" {
|
|
cfg.LLMAPIBaseURL = req.LLMAPIBaseURL
|
|
}
|
|
if req.LLMModelName != "" {
|
|
cfg.LLMModelName = req.LLMModelName
|
|
}
|
|
if req.LLMAPIKey != "" {
|
|
cfg.LLMAPIKey = req.LLMAPIKey
|
|
}
|
|
|
|
// Persist to database (use a simple key-value table)
|
|
db.DB.Exec(`CREATE TABLE IF NOT EXISTS settings (
|
|
key_name varchar(64) NOT NULL PRIMARY KEY,
|
|
value text NOT NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`)
|
|
|
|
db.DB.Exec("REPLACE INTO settings (key_name, value) VALUES (?, ?)", "llm_api_base_url", cfg.LLMAPIBaseURL)
|
|
db.DB.Exec("REPLACE INTO settings (key_name, value) VALUES (?, ?)", "llm_model_name", cfg.LLMModelName)
|
|
if req.LLMAPIKey != "" {
|
|
db.DB.Exec("REPLACE INTO settings (key_name, value) VALUES (?, ?)", "llm_api_key", cfg.LLMAPIKey)
|
|
}
|
|
|
|
success(w, nil)
|
|
}
|