Wrong in UnmarshalJsonReader
Describe the bug I faced a minor problem when I used it. API's JSON response can't used in API's JSON request.It's improtent for some P2P communicate Server.
To Reproduce Steps to reproduce the behavior, if applicable:
-
The api code is
type request { Bytes []byte `json:"bytes"` Name string `json:"name"`
}
type response {}
service template {
@handler postDataTest
post /test (request) returns (response) // this API just simply fmt.Printf("receive :%s",request)
@handler getJsonData
get /get returns (request)
}
2. `/get` API returns Struct like this,or some other []byte like Hash256 result, pubKey....
```go
types.Request{
Bytes: []byte("11122344wsss"),
Name: "test",
}
-
I visit
/getand passgetresult into/test -
some error happend
fullName:bytes, error:string:MTExMjIzNDR3c3Nz, error: `invalid character 'M' looking for beginning of value```
Expected behavior
Logic code in /test print "["11122344wsss","test"]" in console
Screenshots
Environments (please complete the following information):
- OS: Windows10
- go-zero version 1.2.1
- goctl version 1.7.2
More description I fixed it, and I alse make a pr. You can review it in the test file
Would you please give a demo code to reproduce this issue?
- make a main.api ,and code as follow
syntax = "v1"
info (
title: "type title here"
desc: "type desc here"
author: "type author here"
email: "type email here"
version: "type version here"
)
type request {
Bytes []byte `json:"bytes"`
Name string `json:"name"`
}
type response {}
service template {
@handler postDataTest
post /test (request) returns (response)
@handler getJsonData
get /get returns (request)
}
- run the bash like to make a go-zero file
goctl api go --api main.api --dir ./ --style=goZero
- and code in the
internal/logic/getJsonDataLogic.go,add this
func (l *GetJsonDataLogic) GetJsonData() (resp *types.Request, err error) {
return &types.Request{
Bytes: []byte("11122344wsss"),
Name: "test",
}, nil
}
- then visit
/get,I got
{
"bytes": "MTExMjIzNDR3c3Nz",
"name": "test"
}
- pass reslut to
/test,like this:
then ,error happend
and you can run in https://github.com/zeromicro/go-zero/pull/4397/files (the test func)
by the way I also probably fix it ,and I also make a pr ( https://github.com/zeromicro/go-zero/pull/4397)
This issue is stale because it has been open for 30 days with no activity.