diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-21 18:12:49 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-21 18:12:49 +0900 |
| commit | 2512da7ca57dc4c52900417a50daf4f6f2f74054 (patch) | |
| tree | 6a4921a9fcd2fe774171795425ba04889c9c8a49 /backend/main.go | |
| parent | e3373eb48b8cd5eef61a59d8ff590db184612294 (diff) | |
| download | iosdc-japan-2024-albatross-2512da7ca57dc4c52900417a50daf4f6f2f74054.tar.gz iosdc-japan-2024-albatross-2512da7ca57dc4c52900417a50daf4f6f2f74054.tar.zst iosdc-japan-2024-albatross-2512da7ca57dc4c52900417a50daf4f6f2f74054.zip | |
add sqldef and sqlc
Diffstat (limited to 'backend/main.go')
| -rw-r--r-- | backend/main.go | 41 |
1 files changed, 7 insertions, 34 deletions
diff --git a/backend/main.go b/backend/main.go index f0121ef..ae39b46 100644 --- a/backend/main.go +++ b/backend/main.go @@ -56,7 +56,6 @@ func loadEnv() (*Config, error) { const ( gameTypeGolf = "golf" - gameTypeRace = "race" ) const ( @@ -68,24 +67,12 @@ const ( type Game struct { GameID int `db:"game_id"` - // "golf" or "race" + // "golf" Type string `db:"type"` CreatedAt string `db:"created_at"` State string `db:"state"` } -func initDB() error { - _, err := db.Exec(` - CREATE TABLE IF NOT EXISTS games ( - game_id SERIAL PRIMARY KEY, - type VARCHAR(255) NOT NULL, - created_at TIMESTAMP NOT NULL DEFAULT NOW(), - state VARCHAR(255) NOT NULL - ); - `) - return err -} - var gameHubs = map[int]*GameHub{} func startGame(game *Game) { @@ -127,8 +114,7 @@ func handleGolfPost(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, fmt.Sprintf("/golf/%d/%s/", waitingGame.GameID, yourTeam), http.StatusSeeOther) } -func handleRacePost(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/race/1/a/", http.StatusSeeOther) +func handleApiLogin(w http.ResponseWriter, r *http.Request) { } func main() { @@ -151,22 +137,13 @@ func main() { } defer db.Close() - err = initDB() - if err != nil { - log.Fatalf("Error initializing db %v", err) - } - server := http.NewServeMux() server.HandleFunc("GET /assets/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./public"+r.URL.Path) }) - server.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "./public/index.html") - }) - - server.HandleFunc("GET /golf/{$}", func(w http.ResponseWriter, r *http.Request) { + server.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "./public/index.html") }) @@ -174,10 +151,6 @@ func main() { handleGolfPost(w, r) }) - server.HandleFunc("GET /golf/{gameId}/watch/{$}", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "./public/index.html") - }) - server.HandleFunc("GET /sock/golf/{gameId}/watch/{$}", func(w http.ResponseWriter, r *http.Request) { gameId := r.PathValue("gameId") gameIdInt, err := strconv.Atoi(gameId) @@ -199,10 +172,6 @@ func main() { serveWsWatcher(hub, w, r) }) - server.HandleFunc("GET /golf/{gameId}/{team}/{$}", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "./public/index.html") - }) - server.HandleFunc("GET /sock/golf/{gameId}/{team}/{$}", func(w http.ResponseWriter, r *http.Request) { gameId := r.PathValue("gameId") gameIdInt, err := strconv.Atoi(gameId) @@ -225,6 +194,10 @@ func main() { serveWs(hub, w, r, team) }) + server.HandleFunc("POST /api/login/{$}", func(w http.ResponseWriter, r *http.Request) { + handleApiLogin(w, r) + }) + defer func() { for _, hub := range gameHubs { hub.Close() |
