Minor code reorganization and polishing

This commit is contained in:
2022-03-06 14:53:15 +01:00
parent 0f22ca3437
commit c76e078682
5 changed files with 165 additions and 162 deletions
+2 -2
View File
@@ -5,8 +5,7 @@ import (
"net/http"
)
type H map[string]interface{}
// WriteJSON returns the data as json to the client.
func WriteJSON(w http.ResponseWriter, data interface{}) {
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(data)
@@ -15,6 +14,7 @@ func WriteJSON(w http.ResponseWriter, data interface{}) {
}
}
// ReadJSON decodes the request body inside the given pointer.
func ReadJSON(r *http.Request, data interface{}) error {
return json.NewDecoder(r.Body).Decode(data)
}