master tools/goctl/v1.4.3
Kevin Wan 2 years ago committed by GitHub
parent a49f9060c2
commit f76b976262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

File diff suppressed because it is too large Load Diff

@ -3628,6 +3628,54 @@ func TestUnmarshalJsonReaderWithMismatchTypeBoolMap(t *testing.T) {
}, &req)) }, &req))
} }
func TestUnmarshalJsonBytesSliceOfMaps(t *testing.T) {
input := []byte(`{
"order_id": "1234567",
"refund_reason": {
"reason_code": [
123,
234
],
"desc": "not wanted",
"show_reason": [
{
"123": "not enough",
"234": "closed"
}
]
},
"product_detail": {
"product_id": "123",
"sku_id": "123",
"name": "cake",
"actual_amount": 100
}
}`)
type (
RefundReasonData struct {
ReasonCode []int `json:"reason_code"`
Desc string `json:"desc"`
ShowReason []map[string]string `json:"show_reason"`
}
ProductDetailData struct {
ProductId string `json:"product_id"`
SkuId string `json:"sku_id"`
Name string `json:"name"`
ActualAmount int `json:"actual_amount"`
}
OrderApplyRefundReq struct {
OrderId string `json:"order_id"`
RefundReason RefundReasonData `json:"refund_reason,optional"`
ProductDetail ProductDetailData `json:"product_detail,optional"`
}
)
var req OrderApplyRefundReq
assert.NoError(t, UnmarshalJsonBytes(input, &req))
}
func BenchmarkDefaultValue(b *testing.B) { func BenchmarkDefaultValue(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
var a struct { var a struct {

@ -210,8 +210,8 @@ func isRightInclude(b byte) (bool, error) {
} }
} }
func maybeNewValue(field reflect.StructField, value reflect.Value) { func maybeNewValue(fieldType reflect.Type, value reflect.Value) {
if field.Type.Kind() == reflect.Ptr && value.IsNil() { if fieldType.Kind() == reflect.Ptr && value.IsNil() {
value.Set(reflect.New(value.Type().Elem())) value.Set(reflect.New(value.Type().Elem()))
} }
} }

Loading…
Cancel
Save