diff --git a/plugin_novel/qianbi.go b/plugin_novel/qianbi.go index e37b7775..79ca3698 100644 --- a/plugin_novel/qianbi.go +++ b/plugin_novel/qianbi.go @@ -19,7 +19,7 @@ import ( "github.com/wdvxdr1123/ZeroBot/utils/helper" "github.com/FloatTech/ZeroBot-Plugin/control" - "github.com/FloatTech/ZeroBot-Plugin/utils/encode" + ub "github.com/FloatTech/ZeroBot-Plugin/utils/binary" ) const ( @@ -130,12 +130,12 @@ func login(username, password string) { client := &http.Client{ Jar: gCurCookieJar, } - usernameData, err := encode.Utf8ToGbk(helper.StringToBytes(username)) + usernameData, err := ub.UTF82GBK(helper.StringToBytes(username)) if err != nil { log.Errorln("[novel]", err) } usernameGbk := helper.BytesToString(usernameData) - passwordData, err := encode.Utf8ToGbk(helper.StringToBytes(password)) + passwordData, err := ub.UTF82GBK(helper.StringToBytes(password)) if err != nil { log.Errorln("[novel]", err) } @@ -154,7 +154,7 @@ func login(username, password string) { } func search(searchKey string) (searchHtml string) { - searchKeyData, err := encode.Utf8ToGbk(helper.StringToBytes(searchKey)) + searchKeyData, err := ub.UTF82GBK(helper.StringToBytes(searchKey)) if err != nil { log.Errorln("[novel]", err) } @@ -177,7 +177,7 @@ func search(searchKey string) (searchHtml string) { if err != nil { log.Errorf("[novel] get response for url=%s got error=%s\n", searchURL, err.Error()) } - searchData, err = encode.GbkToUtf8(searchData) + searchData, err = ub.GBK2UTF8(searchData) if err != nil { log.Errorln("[novel]", err) } diff --git a/utils/encode/encode.go b/utils/binary/encode.go similarity index 75% rename from utils/encode/encode.go rename to utils/binary/encode.go index 9b31d1d1..125c13a2 100644 --- a/utils/encode/encode.go +++ b/utils/binary/encode.go @@ -1,4 +1,4 @@ -package encode +package binary import ( "bytes" @@ -8,8 +8,8 @@ import ( "golang.org/x/text/transform" ) -// GBK 转 UTF-8 -func GbkToUtf8(s []byte) ([]byte, error) { +// GBK2UTF8 GBK 转 UTF-8 +func GBK2UTF8(s []byte) ([]byte, error) { reader := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GBK.NewDecoder()) d, e := ioutil.ReadAll(reader) if e != nil { @@ -18,8 +18,8 @@ func GbkToUtf8(s []byte) ([]byte, error) { return d, nil } -// UTF-8 转 GBK -func Utf8ToGbk(s []byte) ([]byte, error) { +// UTF82GBK UTF-8 转 GBK +func UTF82GBK(s []byte) ([]byte, error) { reader := transform.NewReader(bytes.NewReader(s), simplifiedchinese.GBK.NewEncoder()) d, e := ioutil.ReadAll(reader) if e != nil {