mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-03-21 17:44:58 -05:00
42 lines
832 B
Go
42 lines
832 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
"wwfc/qr2"
|
|
)
|
|
|
|
func HandleGroups(w http.ResponseWriter, r *http.Request) {
|
|
u, err := url.Parse(r.URL.String())
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
query, err := url.ParseQuery(u.RawQuery)
|
|
if err != nil {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
groups := qr2.GetGroups(query["game"], query["id"], true)
|
|
|
|
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)
|
|
}
|