Skip to content

Commit

Permalink
Add json encoder instead of marshal all record at once
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Dec 4, 2020
1 parent d2c71b9 commit 4a95274
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions web/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,23 @@ func DBSGetHandler(w http.ResponseWriter, r *http.Request, a string) (int, int64
rec["error"] = fmt.Sprintf("not implemented API %s", api)
records = append(records, rec)
}
data, err := json.Marshal(records)
if err != nil {
return http.StatusInternalServerError, 0, err
var size int64
enc := json.NewEncoder(w)
for _, rec := range records {
err := enc.Encode(rec)
size += int64(binary.Size(rec))
if err != nil {
return http.StatusInternalServerError, 0, err
}

}
// data, err := json.Marshal(records)
// if err != nil {
// return http.StatusInternalServerError, 0, err
// }
w.WriteHeader(status)
w.Write(data)
size := int64(binary.Size(data))
// w.Write(data)
// size := int64(binary.Size(data))
return status, size, nil
}

Expand Down

0 comments on commit 4a95274

Please sign in to comment.