Hacker News new | ask | show | jobs
by thatusernametho 3412 days ago
Quick question: Since Go's html parsing requires utf-8 encoding is there a way to convert the response to utf-8 without ioutil.ReadAll()? (Still pretty new to Go).
1 comments

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.

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