Is there a function built-in or in a supported package to get a *golang.org/x/text/encoding.Encoder
(Decoder
) based on an input charset string such as ISO-8859-1
or ISO-8859-15
? Right now the only way I see to do it is to match it myself:
func getEncoderForCharset(charset string) *encoding.Encoder {
switch charset {
case "ISO-8859-1":
return charmap.ISO8859_1.NewEncoder()
case "ISO-8859-15":
return charmap.ISO8859_15.NewEncoder()
// etc.
}
panic("Unknown charset \"" + charset + "\".")
}