O
O
Oleg Shevelev2016-05-07 22:49:15
go
Oleg Shevelev, 2016-05-07 22:49:15

Which of the libraries for converting http to utf-8 should I choose? Who used what?

There are two libraries for transparent conversion to utf8 via io.Reader
https://godoc.org/golang.org/x/net/html/charset

  • not used before
  • there is an example where resp.Header.Get("Content-Type") is perfectly understood in which "text/html; charset=cp1251" and not just "p1251" http://ru.stackoverflow.com/questions/440217/Probl. ..

https://code.google.com/archive/p/go-charset/
  • used to convert xml on the fly, proved to be excellent, no problems were noticed
  • suitable for encoding/xml.Decoder.CharsetReader = charset.NewReader unlike golang.org/x/net/html/charset
  • it seems like it was transferred to the archive, it’s not convenient to use it directly without a fork, but the fork has been around for a long time
  • not only does "text/html; charset=cp1251" not understand, but "cp1251" must be specified as "windows-1251"

Right now I don’t really want to compare the number of encodings in the forehead, but maybe someone has an opinion on how to compare them in a laconic way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2016-05-08
@bitver

Well, you wrote nonsense.

// Convert the designated charset HTML to utf-8 encoded HTML.
// `charset` being one of the charsets known by the iconv package.
utfBody, err := iconv.NewReader(res.Body, charset, "utf-8")
if err != nil {
    // handler error
}

You need it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question