Commit 873ce517 authored by Lukas Böhm's avatar Lukas Böhm 🎱
Browse files

fix sendJSON

parent ce0ac207
......@@ -48,8 +48,7 @@ func AllShares(w http.ResponseWriter, r *http.Request) *HTTPError {
if err != nil {
return &HTTPError{err, "Can't fetch data", 500}
}
SendJSON(w, shares)
return nil
return SendJSON(w, shares)
}
......@@ -83,8 +82,7 @@ func GetShare(w http.ResponseWriter, r *http.Request) *HTTPError {
return &HTTPError{err, "wrong password", 401}
}
SendJSON(w, share)
return nil
return SendJSON(w, share)
}
......@@ -167,8 +165,7 @@ func OpenShare(w http.ResponseWriter, r *http.Request) *HTTPError {
// return 201
w.WriteHeader(http.StatusCreated)
SendJSON(w, newShare)
return nil
return SendJSON(w, newShare)
}
......@@ -206,8 +203,7 @@ func CloseShare(w http.ResponseWriter, r *http.Request) *HTTPError {
return &HTTPError{err, "Can't edit data", 500}
}
SendJSON(w, share)
return nil
return SendJSON(w, share)
}
......@@ -258,8 +254,7 @@ func UploadAttachment(w http.ResponseWriter, r *http.Request) *HTTPError {
}
w.WriteHeader(http.StatusCreated)
SendJSON(w, att)
return nil
return SendJSON(w, att)
}
......@@ -283,12 +278,10 @@ func ConfigureRoutes() {
log.Fatal(http.ListenAndServe(":6969", handler))
}
func SendJSON(w http.ResponseWriter, res interface{}) {
func SendJSON(w http.ResponseWriter, res interface{}) *HTTPError {
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(res)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
return &HTTPError{err, "Can't encode data", 500}
}
func SendMail(receiver string) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment