From 9d034c77a5a226cbefd51a2faed35b750398d229 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 25 Jan 2017 17:27:07 +0000 Subject: [PATCH] Initial rageshake server --- scripts/rageshake.go | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 scripts/rageshake.go diff --git a/scripts/rageshake.go b/scripts/rageshake.go new file mode 100644 index 000000000..883dd4fa1 --- /dev/null +++ b/scripts/rageshake.go @@ -0,0 +1,53 @@ +// Run a web server capable of dumping bug reports sent by Riot. +// Requires Go 1.5+ +// Usage: go run rageshake.go PORT +// Example: go run rageshake.go 8080 +package main + +import ( + "encoding/json" + "fmt" + "log" + "net/http" + "os" +) + +type LogEntry struct { + ID string `json:"id"` + Lines string `json:"lines"` +} + +type Payload struct { + Text string `json:"text"` + Version string `json:"version"` + UserAgent string `json:"user_agent"` + Logs []LogEntry `json:"logs"` +} + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { + if req.Method != "POST" && req.Method != "OPTIONS" { + w.WriteHeader(405) + return + } + // Set CORS + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") + w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept") + if req.Method == "OPTIONS" { + return; + } + var p Payload + if err := json.NewDecoder(req.Body).Decode(&p); err != nil { + w.WriteHeader(400) + w.Write([]byte("Body is not JSON")) + return + } + // Dump bug report to disk + fmt.Println(p) + + }) + + port := os.Args[1] + log.Fatal(http.ListenAndServe(":"+port, nil)) +}