mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-07-18 16:51:25 -05:00
Merge pull request #39 from MikeIsAStar/do-not-return-null-when-no-groups-exist
API: Do not return 'null' when no groups exist
This commit is contained in:
commit
989b5c2477
|
|
@ -10,8 +10,6 @@ import (
|
|||
)
|
||||
|
||||
func HandleGroups(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
u, err := url.Parse(r.URL.String())
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
|
@ -47,12 +45,18 @@ func HandleGroups(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
jsonData, err := json.Marshal(groups)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
var jsonData []byte
|
||||
if len(groups) == 0 {
|
||||
jsonData, _ = json.Marshal([]string{})
|
||||
} else {
|
||||
jsonData, err = json.Marshal(groups)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(jsonData)))
|
||||
w.Write(jsonData)
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ type Stats struct {
|
|||
}
|
||||
|
||||
func HandleStats(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
u, err := url.Parse(r.URL.String())
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
|
@ -85,6 +83,7 @@ func HandleStats(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Content-Length", strconv.Itoa(len(jsonData)))
|
||||
w.Write(jsonData)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user