mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-09 20:10:25 +08:00
增加服务之间拷贝配置的API(开源版本只有定义,没有完全实现)
This commit is contained in:
51
internal/utils/json_test.go
Normal file
51
internal/utils/json_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJSONClone(t *testing.T) {
|
||||
type user struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
|
||||
var u = &user{
|
||||
Name: "Jack",
|
||||
Age: 20,
|
||||
}
|
||||
|
||||
newU, err := utils.JSONClone[*user](u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("%#v", newU)
|
||||
}
|
||||
|
||||
func TestJSONClone_Slice(t *testing.T) {
|
||||
type user struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
|
||||
var u = []*user{
|
||||
{
|
||||
Name: "Jack",
|
||||
Age: 20,
|
||||
},
|
||||
{
|
||||
Name: "Lily",
|
||||
Age: 18,
|
||||
},
|
||||
}
|
||||
|
||||
newU, err := utils.JSONClone[[]*user](u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
logs.PrintAsJSON(newU, t)
|
||||
}
|
||||
Reference in New Issue
Block a user