Answers so far haven't addressed the "entire stream" part of the question. I think the good way to do this is ioutil.ReadAll
. With your io.ReaderCloser
named rc
, I would write,
Go >= v1.16
if b, err := io.ReadAll(rc); err == nil {
return string(b)
} ...
Go <= v1.15
if b, err := ioutil.ReadAll(rc); err == nil {
return string(b)
} ...