1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-10-18 05:14:19 +00:00
sii/cmd/sii-editor/api.go
Knut Ahlers ab39609f45
Implement Save-Game Editor (#1)
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-12-28 13:06:28 +00:00

29 lines
585 B
Go

package main
import (
"encoding/json"
"net/http"
)
func apiGenericError(w http.ResponseWriter, status int, err error) {
var eString = "undefined error"
if err != nil {
eString = err.Error()
}
data := map[string]interface{}{
"code": status,
"error": eString,
"success": false,
}
apiGenericJSONResponse(w, status, data)
}
func apiGenericJSONResponse(w http.ResponseWriter, status int, data interface{}) {
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(data)
}