Simplify apiHandler.
This commit is contained in:
+13
-7
@@ -124,7 +124,16 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
first, kind, rest := splitPath(r.URL.Path[len("/galene-api"):])
|
first, kind, rest := splitPath(r.URL.Path[len("/galene-api"):])
|
||||||
if first == "/v0" && kind == ".stats" && rest == "" {
|
if first != "/v0" {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch kind {
|
||||||
|
case ".stats":
|
||||||
|
if rest != "" {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
if apiCORS(w, r, "HEAD, GET") {
|
if apiCORS(w, r, "HEAD, GET") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -137,14 +146,11 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
w.Header().Set("cache-control", "no-cache")
|
w.Header().Set("cache-control", "no-cache")
|
||||||
sendJSON(w, r, stats.GetGroups())
|
sendJSON(w, r, stats.GetGroups())
|
||||||
return
|
case ".groups":
|
||||||
} else if first == "/v0" && kind == ".groups" {
|
|
||||||
apiGroupHandler(w, r, rest)
|
apiGroupHandler(w, r, rest)
|
||||||
return
|
default:
|
||||||
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
http.NotFound(w, r)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
|
func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user