完成v1版本动态结构体创建

This commit is contained in:
2024-08-21 18:16:21 +08:00
parent e4cef0855e
commit 18351f3b29
4 changed files with 145 additions and 16 deletions

27
dynamic_struct_test.go Normal file
View File

@ -0,0 +1,27 @@
// Package wrapper ...
//
// Description : wrapper ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-08-21 17:56
package wrapper
import (
"fmt"
"github.com/mitchellh/mapstructure"
"testing"
)
func TestNewDynamic(t *testing.T) {
instance := NewDynamic()
instance.AddInt("Age", "age", "")
instance.AddString("Name", "name", "")
defaultVal := instance.ToStructDefaultValue()
testMap := map[string]any{
"name": "白茶",
"age": 18,
}
_ = mapstructure.Decode(testMap, &defaultVal)
fmt.Println(defaultVal)
}