added a json handler
This commit is contained in:
parent
a8ceec3d6b
commit
97f18f1df2
@ -14,6 +14,13 @@ type prob struct {
|
||||
Last int
|
||||
}
|
||||
|
||||
type JsonHandler func(http.ResponseWriter, *http.Request)
|
||||
|
||||
func (h JsonHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
h(w, req)
|
||||
}
|
||||
|
||||
func problem(w http.ResponseWriter, req *http.Request) {
|
||||
operation := "+"
|
||||
if r := rand.Intn(2); r == 0 {
|
||||
|
4
main.go
4
main.go
@ -21,8 +21,8 @@ func main() {
|
||||
flag.Parse()
|
||||
http.Handle("/",
|
||||
http.FileServer(http.Dir(*static_files)))
|
||||
http.HandleFunc("/api/v0/attempt/", attempt)
|
||||
http.HandleFunc("/api/v0/problem/", problem)
|
||||
http.HandleFunc("/api/v0/attempt/", JsonHandler(attempt))
|
||||
http.Handle("/api/v0/problem/", JsonHandler(problem))
|
||||
if err := http.ListenAndServe(*addr, nil); err != nil {
|
||||
log.Fatal("ListenAndServe:", err)
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ function update_board(f, o, s, score) {
|
||||
|
||||
function new_problem() {
|
||||
$.get("/api/v0/problem/", function(d) {
|
||||
update_board(d["first"], d["operation"], d["second"], d["score"]);
|
||||
update_board(d["First"], d["Operation"], d["Second"], d["Score"]);
|
||||
$("#answer").val("");
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user