github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/jsoni/value_tests/iface_test.go (about) 1 package test 2 3 import "io" 4 5 func init() { 6 pCloser1 := func(str string) *io.Closer { 7 closer := io.Closer(strCloser1(str)) 8 return &closer 9 } 10 pCloser2 := func(str string) *io.Closer { 11 strCloser := strCloser2(str) 12 closer := io.Closer(&strCloser) 13 return &closer 14 } 15 marshalCases = append(marshalCases, 16 pCloser1("hello"), 17 pCloser2("hello"), 18 ) 19 unmarshalCases = append(unmarshalCases, unmarshalCase{ 20 ptr: (*[]io.Closer)(nil), 21 input: "[null]", 22 }, unmarshalCase{ 23 obj: func() interface{} { 24 strCloser := strCloser2("") 25 return &struct { 26 Field io.Closer 27 }{ 28 &strCloser, 29 } 30 }, 31 input: `{"Field": "hello"}`, 32 }) 33 } 34 35 type strCloser1 string 36 37 func (closer strCloser1) Close() error { 38 return nil 39 } 40 41 type strCloser2 string 42 43 func (closer *strCloser2) Close() error { 44 return nil 45 }