mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 16:42:41 +08:00
结构体转map
This commit is contained in:
25
structs/struct_to_map_test.go
Normal file
25
structs/struct_to_map_test.go
Normal file
@ -0,0 +1,25 @@
|
||||
package structs_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/charlienet/go-mixed/structs"
|
||||
)
|
||||
|
||||
func TestStructToMap(t *testing.T) {
|
||||
o := struct {
|
||||
Abc string
|
||||
InTagName string `json:"in_tag_name,omitempty"`
|
||||
KeepEmpty int
|
||||
OmitEmpty int `json:",omitempty"`
|
||||
}{
|
||||
Abc: "测试字段",
|
||||
InTagName: "具体名称",
|
||||
KeepEmpty: 0,
|
||||
OmitEmpty: 0,
|
||||
}
|
||||
|
||||
t.Log(structs.ToMap(o))
|
||||
t.Log(structs.ToMap(o, structs.IgnoreEmpty()))
|
||||
t.Log(structs.ToMap(o, structs.Omitempty()))
|
||||
}
|
Reference in New Issue
Block a user