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,80 @@
|
||||
package scripts
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"log"
|
||||
)
|
||||
|
||||
//go:embed sample_data.json
|
||||
var dataJSON []byte
|
||||
|
||||
var SCRIPTS []Script
|
||||
|
||||
func init() {
|
||||
if err := json.Unmarshal(dataJSON, &SCRIPTS); err != nil {
|
||||
log.Fatalf("failed to parse sample_data.json: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type Script struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Type string `json:"type"`
|
||||
Difficulty int `json:"difficulty"`
|
||||
PlayerCount PlayerCount `json:"playerCount"`
|
||||
Duration string `json:"duration"`
|
||||
Background string `json:"background"`
|
||||
Phases []Phase `json:"phases"`
|
||||
Roles []Role `json:"roles"`
|
||||
Clues []Clue `json:"clues"`
|
||||
Truth string `json:"truth"`
|
||||
}
|
||||
|
||||
type PlayerCount struct {
|
||||
Min int `json:"min"`
|
||||
Max int `json:"max"`
|
||||
}
|
||||
|
||||
type Phase struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
PublicInfo string `json:"publicInfo"`
|
||||
Clues []string `json:"clues"`
|
||||
}
|
||||
|
||||
type Role struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
PublicProfile string `json:"publicProfile"`
|
||||
SecretProfile string `json:"secretProfile"`
|
||||
Secret string `json:"secret"`
|
||||
Goal string `json:"goal"`
|
||||
WinCondition string `json:"winCondition"`
|
||||
Personality string `json:"personality"`
|
||||
}
|
||||
|
||||
type Clue struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Phase int `json:"phase"`
|
||||
}
|
||||
|
||||
func GetByID(id string) *Script {
|
||||
for i := range SCRIPTS {
|
||||
if SCRIPTS[i].ID == id {
|
||||
return &SCRIPTS[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetByTitle(title string) *Script {
|
||||
for i := range SCRIPTS {
|
||||
if SCRIPTS[i].Title == title {
|
||||
return &SCRIPTS[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user