Add content-type to API responses

This commit is contained in:
Alexey Khit
2023-05-28 06:37:59 +03:00
parent 1612f9c81e
commit 0e270081fe
7 changed files with 42 additions and 27 deletions
+4 -4
View File
@@ -1,8 +1,8 @@
package homekit
import (
"encoding/json"
"fmt"
"github.com/AlexxIT/go2rtc/internal/api"
"github.com/AlexxIT/go2rtc/internal/app/store"
"github.com/AlexxIT/go2rtc/internal/streams"
"github.com/AlexxIT/go2rtc/pkg/hap"
@@ -54,7 +54,7 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
items = append(items, device)
}
_ = json.NewEncoder(w).Encode(items)
api.ResponseJSON(w, items)
case "POST":
// TODO: post params...
@@ -64,14 +64,14 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
if err := hkPair(id, pin, name); err != nil {
log.Error().Err(err).Caller().Send()
_, err = w.Write([]byte(err.Error()))
http.Error(w, err.Error(), http.StatusInternalServerError)
}
case "DELETE":
src := r.URL.Query().Get("src")
if err := hkDelete(src); err != nil {
log.Error().Err(err).Caller().Send()
_, err = w.Write([]byte(err.Error()))
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}