服务发现基础逻辑

This commit is contained in:
2024-10-12 00:38:18 +08:00
parent d1d7f56ce4
commit e6f5aaa02f
10 changed files with 216 additions and 31 deletions
+23
View File
@@ -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
}