fix: add utf8 encoder for outputter

pull/144/head
ᴍᴏᴏɴD4ʀᴋ 2 years ago
parent 645e2608a2
commit d1ae09d9e4
  1. 1
      go.mod
  2. 2
      go.sum
  3. 4
      internal/browingdata/outputter.go

@ -16,6 +16,7 @@ require (
github.com/urfave/cli/v2 v2.4.0 github.com/urfave/cli/v2 v2.4.0
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
golang.org/x/exp v0.0.0-20220414153411-bcd21879b8fd golang.org/x/exp v0.0.0-20220414153411-bcd21879b8fd
golang.org/x/text v0.3.6
) )
require ( require (

@ -90,6 +90,8 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=

@ -9,6 +9,8 @@ import (
"github.com/gocarina/gocsv" "github.com/gocarina/gocsv"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
) )
type OutPutter struct { type OutPutter struct {
@ -35,7 +37,7 @@ func (o *OutPutter) Write(data Source, writer io.Writer) error {
return encoder.Encode(data) return encoder.Encode(data)
default: default:
gocsv.SetCSVWriter(func(w io.Writer) *gocsv.SafeCSVWriter { gocsv.SetCSVWriter(func(w io.Writer) *gocsv.SafeCSVWriter {
writer := csv.NewWriter(w) writer := csv.NewWriter(transform.NewWriter(w, unicode.UTF8BOM.NewEncoder()))
writer.Comma = ',' writer.Comma = ','
return gocsv.NewSafeCSVWriter(writer) return gocsv.NewSafeCSVWriter(writer)
}) })

Loading…
Cancel
Save