From d1ae09d9e4bb0634e7b6e61118366f83757e30e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=8D=E1=B4=8F=E1=B4=8F=C9=B4D4=CA=80=E1=B4=8B?= Date: Sun, 5 Jun 2022 15:15:41 +0800 Subject: [PATCH] fix: add utf8 encoder for outputter --- go.mod | 1 + go.sum | 2 ++ internal/browingdata/outputter.go | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7df5a94..f2418f0 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/urfave/cli/v2 v2.4.0 golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 golang.org/x/exp v0.0.0-20220414153411-bcd21879b8fd + golang.org/x/text v0.3.6 ) require ( diff --git a/go.sum b/go.sum index b84743f..2bf7b3f 100644 --- a/go.sum +++ b/go.sum @@ -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/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/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/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/internal/browingdata/outputter.go b/internal/browingdata/outputter.go index 3d80beb..4b2c43c 100644 --- a/internal/browingdata/outputter.go +++ b/internal/browingdata/outputter.go @@ -9,6 +9,8 @@ import ( "github.com/gocarina/gocsv" jsoniter "github.com/json-iterator/go" + "golang.org/x/text/encoding/unicode" + "golang.org/x/text/transform" ) type OutPutter struct { @@ -35,7 +37,7 @@ func (o *OutPutter) Write(data Source, writer io.Writer) error { return encoder.Encode(data) default: gocsv.SetCSVWriter(func(w io.Writer) *gocsv.SafeCSVWriter { - writer := csv.NewWriter(w) + writer := csv.NewWriter(transform.NewWriter(w, unicode.UTF8BOM.NewEncoder())) writer.Comma = ',' return gocsv.NewSafeCSVWriter(writer) })