I have an application which is reading a large number of requests (approx 4-5 million reqs / second)
I am using json.decoder to read my incoming json data from the request body.
my code :
err := json.NewDecoder(c.Request.Body).Decode(&obj)
The above code snippet drains the request body. Is there any way I could stream it back so it can be read again in the code?
For instance, while using the io util library, I could just do :
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
The solution I'm looking at is something like :
err := json.NewDecoder(c.Request.Body).Decode(&obj)
if err != nil {
return err
}
b := new(bytes.Buffer)
c.Request.Body = json.NewEncoder(b).Encode(obj)
but obviously c.Request.Body = json.NewEncoder(b).Encode(obj)
is not supported
I can't use the ioutil library since it gets very difficult to manage lengthy requests.