-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandles.go
55 lines (38 loc) · 940 Bytes
/
handles.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"encoding/json"
"net/http"
)
type Code struct {
Code []string `json:"code"`
}
type Output struct {
Output string `json:"output"`
}
func StartSandbox(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Ready"))
}
func PlayHandler(w http.ResponseWriter, r *http.Request) {
defer func() {
if e := recover(); e != nil {
var output string = message + "\n" + panicMessage
outputJson, _ := json.Marshal(Output{output})
w.Header().Set("Content-Type", "application/json")
w.Write(outputJson)
} else {
var output string = message
outputJson, _ := json.Marshal(Output{output})
w.Header().Set("Content-Type", "application/json")
w.Write(outputJson)
}
message = ""
panicMessage = ""
}()
var code Code
_ = json.NewDecoder(r.Body).Decode(&code)
p := 0
m := 0
for lineNumber, eachline := range code.Code {
p, m = parse(eachline, lineNumber + 1, p, m)
}
}