...
1
16
17 package issue_test
18
19 import (
20 . `github.com/bytedance/sonic`
21 `fmt`
22 `sync`
23 `testing`
24 )
25
26 func ExtractJson(idx int, body interface{}) {
27 j := []byte(exampleJson[idx])
28
29
30 err := Unmarshal(j, &body)
31 if err != nil {
32 fmt.Println(err.Error())
33 return
34 }
35 }
36
37 var exampleJson1 = `{}`
38
39 var exampleJson2 = `{}`
40
41 var exampleJson = []string{exampleJson1, exampleJson2}
42
43 type raceTestStruct struct {
44 f1 *[]raceTestStruct2 `json:"f1"`
45 f2 *int `json:"f2"`
46 f3 *string `json:"f3"`
47 f4 *string `json:"f4"`
48 }
49 type raceTestStruct2 struct {
50 g1 *string `json:"g1"`
51 g2 *string `json:"g2"`
52 g3 *string `json:"g3"`
53 g4 []raceTestStruct3 `json:"g4"`
54 }
55 type raceTestStruct3 struct {
56 e1 *string `json:"e1"`
57 e2 *string `json:"e2"`
58 e3 *float64 `json:"e3"`
59 e4 *float64 `json:"e4"`
60 }
61
62 func TestExtracJson(t *testing.T) {
63
64 wg := sync.WaitGroup{}
65
66 resultChan := make(chan raceTestStruct, 2)
67
68 wg.Add(1)
69 go func() {
70 defer wg.Done()
71 var model raceTestStruct
72 ExtractJson(0, &model)
73 resultChan <- model
74 }()
75
76 wg.Add(1)
77 go func() {
78 defer wg.Done()
79 var model raceTestStruct
80 ExtractJson(1, &model)
81 resultChan <- model
82 }()
83
84 var results []raceTestStruct
85 for i := 0; i < 2; i++ {
86 results = append(results, <-resultChan)
87 }
88
89 wg.Wait()
90 close(resultChan)
91 }
View as plain text