go-charset
go-charset copied to clipboard
charset error Golang 1.10.3 in custom GOPATH
I had an error while using package:
charset: cannot open "charsets.json": open /usr/local/lib/go-charset/datafiles/charsets.json: no such file or directory
GOPATH set to custom
Possible solution: From:
https://github.com/paulrosania/go-charset/blob/55c9d7a5834c4d034b34bf042103dbc646887f4f/charset/file.go#L24
to
var CharsetDir = "/../datafiles"
And
https://github.com/paulrosania/go-charset/blob/55c9d7a5834c4d034b34bf042103dbc646887f4f/charset/file.go#L34
to
_, filename, _, _ := runtime.Caller(1)
r, err = os.Open(filepath.Join(path.Dir(filename)+CharsetDir, name))
@paulrosania Any news on this? Would you be open to a PR or do you recommend using another package instead of this one?
I don't think this repo is maintained anymore.
Seems like the approach now is to use golang.org/x/text/transform
Yep, transform
seems to be it. I guess it depends on what exactly you're doing but I found some alternatives or wrapping APIs too. I reading CSV files and writing plan text so I've switch to the following alternatives.
Writing - golang.org/x/text/encoding/charmap
fileOnDisk, _ := os.Create(someFile)
latinWriter := charmap.ISO8859_1.NewEncoder().Writer(fileOnDisk)
if _, err := latinWriter.Write([]byte("latin1")); err != nil {
return err
}
Reading - golang.org/x/net/html/charset
This method uses golang.org/x/text/transform
for the reader and determine the encoding for you automatically.
fileOnDisk, _ := os.Open(someFile)
reader, err := charset.NewReader(fileOnDisk, "text/csv")