Hacker News new | ask | show | jobs
by zalmoxes 3412 days ago
html.Parse takes a io.Reader https://github.com/golang/net/blob/master/html/parse.go#L201...

an http Response.Body is a io.ReadCloser so you can pass it directly with `html.Parse(response.Body)`

But don't forget to defer io.Close the body.

1 comments

I guess I wasn't specific enough. I'd like to stream the response so as to use less memory. I also need to ensure the body is utf-8 encoded because that makes Go happy.

https://mionskowski.pl/html-golang-stream-processing