reflection_test.go 512 B

12345678910111213141516171819202122232425262728293031
  1. package reflection
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. type Fakeb struct {
  7. In int `json:"in"`
  8. }
  9. type fake struct {
  10. Name string `json:"name"`
  11. Age int `json:"age"`
  12. Usage *Fakeb `json:"usage"`
  13. }
  14. func TestSetter(t *testing.T) {
  15. dst := &fake{}
  16. ms := map[string]any{"name": "aa", "age": "5", "usage": map[string]any{"in": 15}}
  17. err := Setter(dst, ms)
  18. if err != nil {
  19. t.Error(err)
  20. return
  21. }
  22. if dst.Age != 5 {
  23. t.Errorf("setter failed")
  24. } else {
  25. fmt.Println(dst.Usage.In)
  26. fmt.Printf("%+v", dst)
  27. }
  28. }