Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Fix HTTP response into JSON format #64

Merged
merged 1 commit into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions dispatcher/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (h *IndexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// index documents in bulk
result, err := h.client.IndexDocument(docs)
count, err := h.client.IndexDocument(docs)
if err != nil {
httpStatus = http.StatusInternalServerError

Expand All @@ -252,7 +252,11 @@ func (h *IndexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

content, err = json.MarshalIndent(result, "", " ")
// create JSON content
msgMap := map[string]interface{}{
"count": count,
}
content, err = json.MarshalIndent(msgMap, "", " ")
if err != nil {
httpStatus = http.StatusInternalServerError

Expand Down Expand Up @@ -338,7 +342,7 @@ func (h *DeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// delete documents in bulk
result, err := h.client.DeleteDocument(ids)
count, err := h.client.DeleteDocument(ids)
if err != nil {
httpStatus = http.StatusInternalServerError

Expand All @@ -355,7 +359,11 @@ func (h *DeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

content, err = json.MarshalIndent(result, "", " ")
// create JSON content
msgMap := map[string]interface{}{
"count": count,
}
content, err = json.MarshalIndent(msgMap, "", " ")
if err != nil {
httpStatus = http.StatusInternalServerError

Expand Down
14 changes: 11 additions & 3 deletions indexer/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ func (h *IndexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

content, err = json.MarshalIndent(count, "", " ")
// create JSON content
msgMap := map[string]interface{}{
"count": count,
}
content, err = json.MarshalIndent(msgMap, "", " ")
if err != nil {
httpStatus = http.StatusInternalServerError

Expand Down Expand Up @@ -340,7 +344,7 @@ func (h *DeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// delete documents in bulk
result, err := h.client.DeleteDocument(ids)
count, err := h.client.DeleteDocument(ids)
if err != nil {
httpStatus = http.StatusInternalServerError

Expand All @@ -357,7 +361,11 @@ func (h *DeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

content, err = json.MarshalIndent(result, "", " ")
// create JSON content
msgMap := map[string]interface{}{
"count": count,
}
content, err = json.MarshalIndent(msgMap, "", " ")
if err != nil {
httpStatus = http.StatusInternalServerError

Expand Down