服务发现基础逻辑
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
"golang.org/x/text/transform"
|
||||
"gorm.io/gorm"
|
||||
"testing"
|
||||
"work_cation/pkg/gormx"
|
||||
@@ -154,3 +157,23 @@ func TestInitDB1(t *testing.T) {
|
||||
fmt.Println(ret)
|
||||
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
var name string = "苏通"
|
||||
newName, _ := convertToUTF8(name)
|
||||
|
||||
fmt.Printf(name)
|
||||
fmt.Printf(newName)
|
||||
}
|
||||
|
||||
func convertToUTF8(input string) (string, error) {
|
||||
// 定义其他编码到 UTF-8 的转换器
|
||||
reader := transform.NewReader(bytes.NewReader([]byte(input)), simplifiedchinese.GBK.NewDecoder())
|
||||
|
||||
// 读取转换后的数据
|
||||
buf := new(bytes.Buffer)
|
||||
buf.ReadFrom(reader)
|
||||
utf8Str := buf.String()
|
||||
|
||||
return utf8Str, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user