常用类型及数据操作方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

47 lines
814 B

package helper
import (
"testing"
)
type User struct {
ID int
NAME string
}
type UserString struct {
ID string
NAME string
}
func Test_structColumn(t *testing.T) {
user1 := UserString{
ID: "2",
NAME: "zwk",
}
user2 := UserString{
ID: "3",
NAME: "zzz",
}
var list3 []UserString
list3 = append(list3, user1)
list3 = append(list3, user2)
t.Log(list3)
t.Log("---------------------")
var userMap map[string]string
StructColumn(&userMap, list3, "NAME", "ID")
t.Logf("%#v\n", userMap)
t.Log("---------------------")
var userMap1 map[int]UserString
StructColumn(&userMap1, list3, "", "ID")
t.Logf("%#v\n", userMap1)
t.Log("---------------------")
var userSlice []string
StructColumn(&userSlice, list3, "ID", "")
t.Logf("%#v\n", userSlice)
t.Log("---------------------")
}