diff --git a/a_test.go b/a_test.go deleted file mode 100644 index d9226e2..0000000 --- a/a_test.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "io" - "testing" - - "golang.org/x/text/encoding/simplifiedchinese" - "golang.org/x/text/transform" -) - -// 尝试使用不同编码进行解码 -func tryDecodeWithEncoding(data []byte, decoder transform.Transformer) (string, error) { - reader := transform.NewReader(bytes.NewReader(data), decoder) - decoded, err := io.ReadAll(reader) - if err != nil { - return "", err - } - return string(decoded), nil -} - -// 检测可能的编码 -func detectEncoding(data []byte) { - // 尝试 GBK 解码 - if result, err := tryDecodeWithEncoding(data, simplifiedchinese.GBK.NewDecoder()); err == nil { - fmt.Printf("可能是 GBK 编码: %s\n", result) - } - - // 尝试 GB18030 解码 - if result, err := tryDecodeWithEncoding(data, simplifiedchinese.GB18030.NewDecoder()); err == nil { - fmt.Printf("可能是 GB18030 编码: %s\n", result) - } - - // 尝试 UTF-8 解码(直接输出) - fmt.Printf("原始 UTF-8 输出: %s\n", string(data)) -} - -func TestA(t *testing.T) { - chaos := "凳蹦戎昆储。" - body := []byte(chaos) - - fmt.Println("尝试检测编码...") - detectEncoding(body) - - // 使用 GBK 解码 - reader := transform.NewReader(bytes.NewReader(body), simplifiedchinese.GBK.NewDecoder()) - decoded, err := io.ReadAll(reader) - if err != nil { - fmt.Printf("解码失败: %v\n", err) - return - } - - fmt.Println("GBK 解码结果:", string(decoded)) -} diff --git a/go.mod b/go.mod index 86e9a21..837436b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/go-resty/resty/v2 v2.16.5 github.com/google/uuid v1.6.0 github.com/spf13/cobra v1.9.1 - golang.org/x/text v0.24.0 ) require ( diff --git a/go.sum b/go.sum index 22370b9..84b1afa 100644 --- a/go.sum +++ b/go.sum @@ -77,8 +77,6 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= -golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=