Use STDIN as writer for encoding func's JSON input data instead of buffering

This commit is contained in:
Denis Makogon
2017-09-30 00:52:23 +03:00
parent 0316cd90a1
commit da9629d8dc

View File

@@ -46,18 +46,12 @@ func (h *JSONProtocol) Dispatch(w io.Writer, req *http.Request) error {
Headers: req.Header, Headers: req.Header,
Body: body.String(), Body: body.String(),
} }
b, err := json.Marshal(jin) err := json.NewEncoder(h.in).Encode(&jin)
if err != nil { if err != nil {
// this shouldn't happen // this shouldn't happen
return respondWithError( return respondWithError(
w, fmt.Errorf("error marshalling JSONInput: %s", err.Error())) w, fmt.Errorf("error marshalling JSONInput: %s", err.Error()))
} }
// TODO: write in chunks, how big should chunk be?
_, err = h.in.Write(b)
if err != nil {
return respondWithError(
w, fmt.Errorf("error writing JSON object to function's STDIN: %s", err.Error()))
}
if rw, ok := w.(http.ResponseWriter); ok { if rw, ok := w.(http.ResponseWriter); ok {
// this has to be done for pulling out: // this has to be done for pulling out: