常用类型及数据操作方法
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

  1. package helper
  2. import (
  3. "testing"
  4. )
  5. type User struct {
  6. ID int
  7. NAME string
  8. }
  9. type UserString struct {
  10. ID string
  11. NAME string
  12. }
  13. func Test_structColumn(t *testing.T) {
  14. user1 := UserString{
  15. ID: "2",
  16. NAME: "zwk",
  17. }
  18. user2 := UserString{
  19. ID: "3",
  20. NAME: "zzz",
  21. }
  22. var list3 []UserString
  23. list3 = append(list3, user1)
  24. list3 = append(list3, user2)
  25. t.Log(list3)
  26. t.Log("---------------------")
  27. var userMap map[string]string
  28. StructColumn(&userMap, list3, "NAME", "ID")
  29. t.Logf("%#v\n", userMap)
  30. t.Log("---------------------")
  31. var userMap1 map[int]UserString
  32. StructColumn(&userMap1, list3, "", "ID")
  33. t.Logf("%#v\n", userMap1)
  34. t.Log("---------------------")
  35. var userSlice []string
  36. StructColumn(&userSlice, list3, "ID", "")
  37. t.Logf("%#v\n", userSlice)
  38. t.Log("---------------------")
  39. }