Closed robskie closed 9 years ago
can you elaborate and upload your code ?
So for example you have the following service method:
func (s *TestService) Test(req *http.Request, r *RequestMessage) error {
body, _ := ioutil.ReadAll(req.Body)
// Do something with body
return nil
}
In this case, body
will always be an empty slice regardless of the sent request message. I expect that if the request message is non-empty, body
would also be non-empty.
As for the suggestion that another endpoints tag, endpoints:"-"
, be added for hidden fields, let's say you have the following request message:
type RequestMessage struct {
Field1 int `json:"field1"`
Field2 int `json:"field2"`
Hidden int `json:"hidden"`
}
And you want to have the Hidden
field to be ignored by endpoints but still be able to retrieve its value in service methods. One possible solution would be to change its tag to json:"-"
, and just extract its value from the raw request body.
Another option would be to leave its json tag unchanged and just add another endpoints tag, endpoints:"-"
, which is more convenient since you wouldn't need to manually extract the Hidden
field's value from the request body. This is done automatically by the json unmarshaller if the sent request has it.
Hi!
I'm trying to add some extra field in the request which are not part of the message request definition like what bossylobster suggested here, but I'm always getting an empty request body. Apparently, the request body is read but not restored to its original content when passed to service methods.
EDIT: Another way of adding "hidden" fields would be to add another endpoints tag "-" which will allow tagged fields to be ignored by endpoints and yet still be unpacked if it is added in the request.