I am relatively new to Golang and don't fully understand streams. I have a function (circuit breaker function) that is making Rest calls. I have it working but it is only streaming the "responseBody" back. I would actually like to stream back the entire request of stream back both the Body and the Header together.
When I try to use a similar approach on the "header" then I get an error that the header is not streamable.
Is there a good/best way to accomplish this? Thank you. Below is my function.
func CallWithRetries(req *http.Request, output chan []byte) error {
r := retrier.New(retrier.ConstantBackoff(RETRIES, 100 * time.Millisecond), nil)
attempt := 0
err := r.Run(func() error {
attempt++
resp, err := Client.Do(req)
if err == nil && resp.StatusCode < 299 {
responseBody, err := ioutil.ReadAll(resp.Body)
if err == nil {
output <- responseBody
return err
}
return err
} else if err == nil {
customLogger.LogDebug("Status code was: " , transactionId)
err = fmt.Errorf("Status was %v", resp.StatusCode)
}
return err
})
return err
}