Skip to content

Instantly share code, notes, and snippets.

@rianby64
Created September 14, 2019 17:29
Show Gist options
  • Save rianby64/d09d67d1a090a708d7668791e3efc863 to your computer and use it in GitHub Desktop.
Save rianby64/d09d67d1a090a708d7668791e3efc863 to your computer and use it in GitHub Desktop.
Reader for io.ReadCloser
// Nice reader for request.Body
func readStream(stream io.ReadCloser) (string, error) {
defer stream.Close()
body := ""
buffer := make([]byte, 4)
for {
n, err := stream.Read(buffer)
if err != nil {
if err == io.EOF {
body = body + string(buffer[:n])
break
}
return "", err
}
body = body + string(buffer)
}
return body, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment