New API tested

This commit is contained in:
Bel LaPointe
2020-07-23 21:11:36 -06:00
parent d04ced1e33
commit d572cb5c87
6 changed files with 388 additions and 16 deletions

View File

@@ -27,15 +27,7 @@ func jsonHandler(g storage.Graph) http.Handler {
}{
{
path: "/who/",
foo: httpwho,
},
{
path: "/meet/",
foo: httpmeet,
},
{
path: "/isnow/",
foo: httpisnow,
foo: who,
},
}
@@ -45,8 +37,12 @@ func jsonHandler(g storage.Graph) http.Handler {
foo := route.foo
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
if err := foo(g, w, r); err != nil {
status := http.StatusInternalServerError
if strings.Contains(err.Error(), "collision") {
status = http.StatusConflict
}
b, _ := json.Marshal(map[string]string{"error": err.Error()})
http.Error(w, string(b), http.StatusInternalServerError)
http.Error(w, string(b), status)
}
})
mux.HandleFunc(nopath, http.NotFound)