Closed zyukin closed 6 years ago
There's a panic when processing the request - check branch pr-10 for breakage example (try to regenerate proto for /doc/example/pb
and run /doc/example
).
Struct fields should be initiated before unmarhalling into them - in.B = &BStruct{}
would fix the panic.
Also, code doesn't compile if body
tag points to a primitive type, i.e. int64
- it does not implement proto.Message
interface.
Thank you! Primitive types still don't work, but we can file it as a separate bug. Can you fix the HTTPClient vs new rules, please? https://github.com/zyukin/clay/blob/e0cd213da9bf9653f5a97641611d69774146f760/cmd/protoc-gen-goclay/genhandler/template.go#L357
Primitive types works fine for this example:
service Summator {
rpc Sum(SumRequest) returns (SumResponse) {
option (google.api.http) = {
post: "/v1/example/sum/{a}"
body: "b"
};
}
}
message SumRequest {
int64 a = 1;
int64 b = 2;
}
What's wrong with HTTPClient?
I see, thank you!
At the moment, HTTPClient marshals the whole struct to the Body (like body: '*'
) even if only one field is specified in proto.
https://github.com/utrack/clay/tree/zyukin-fix-unmarshal
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '33' 'http://localhost:12345/v1/example/sum/22'
{
"error": "couldn't parse request: couldn't read request JSON: json: cannot unmarshal number into Go value of type map[string]json.RawMessage"
}
What proto?
Are you from Ozon? It would be much faster if you'd ping me on Slack if so.
Proto in /doc/example/pb
at branch https://github.com/utrack/clay/tree/zyukin-fix-unmarshal
Fix for issue #9