refactor: rewrite backend in Go, replacing Python FastAPI
Port the FastAPI backend to Go 1.26, preserving all API functionality: - auth (register/login/guest/logout/profile/history) with JWT + bcrypt - scripts (list/detail) backed by embedded sample_data.json - games (create/join/start/chat/phase/clue/vote/state/replay) + WebSocket - rule-based NPC agent plus DeepSeek/Ollama AI backends - SQLite persistence via modernc.org/sqlite (pure Go, no cgo) Frontend and documents are unchanged.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
"mmgame/internal/scripts"
|
||||
)
|
||||
|
||||
func ListScripts(w http.ResponseWriter, r *http.Request) {
|
||||
items := []map[string]interface{}{}
|
||||
for _, s := range scripts.SCRIPTS {
|
||||
items = append(items, map[string]interface{}{
|
||||
"id": s.ID,
|
||||
"title": s.Title,
|
||||
"type": s.Type,
|
||||
"difficulty": s.Difficulty,
|
||||
"min_players": s.PlayerCount.Min,
|
||||
"max_players": s.PlayerCount.Max,
|
||||
"duration": s.Duration,
|
||||
"background": s.Background,
|
||||
})
|
||||
}
|
||||
writeJSON(w, 200, items)
|
||||
}
|
||||
|
||||
func GetScript(w http.ResponseWriter, r *http.Request) {
|
||||
scriptID := chi.URLParam(r, "script_id")
|
||||
s := scripts.GetByID(scriptID)
|
||||
if s == nil {
|
||||
writeError(w, 404, "剧本不存在")
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, s)
|
||||
}
|
||||
Reference in New Issue
Block a user