完成v1版本动态结构体创建
This commit is contained in:
27
dynamic_struct_test.go
Normal file
27
dynamic_struct_test.go
Normal 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)
|
||||
}
|
Reference in New Issue
Block a user