1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package main
import (
"fmt"
"net/http"
)
func gameDelete(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
Logger.Printf("Installer: While parsing form: %s", err)
http.Error(w, fmt.Sprintf("Invalid form: %s", err), 400)
return
}
game := r.PostForm.Get("name")
if game == "" {
Logger.Println("Deleter: No game specified")
http.Error(w, "Game param required", 400)
return
}
libMu.RLock()
g, ok := Lib.Games[game]
libMu.RUnlock()
if !ok {
Logger.Printf("Missing: %s", game)
http.Error(w, "Game is missing", 404)
return
}
err = g.Delete()
if err != nil {
Logger.Printf("Error removing game: %s", err)
http.Error(w, fmt.Sprintf("Error removing game: %s", err), 500)
return
}
reloadLib()
http.Redirect(w, r, "/", 302)
}
|