I am using an endpoint similar to the below code
type TestService struct {
gorest.RestService `root:"/test/"`
testPost gorest.EndPoint `method:"POST" path:"/testPost/" postdata:"map[string]string"`
}
I get and handle the posted data, and want to return a payload to the calling client, i.e. success/error and a message.
I cannot make out from the documentation how to achieve this, appending the output
tag and returning anything from the function as per a GET end point fails with the following error;
Parameter list not matching. No matching Method found for EndPoint:[testPost],type:[POST] . Expecting: #func(serv DocumentService) TestPost(PostData map[string]string)# with no return parameters.
Is it possible to return a payload to the client? If not can I redirect to a different end point on success / failure?
So I found a way in case anyone runs into a similar issue.
It seems you can write directly using an instance of the ResponseBuilder, so I create a new response builder, set the content type to json and write my response out!
func(serv DocumentService) TestPost(PostData map[string]string){
fmt.Printf("%+v", PostData)
rb := serv.ResponseBuilder()
rb.AddHeader("Content-Type", "application/json")
rb.Write([]byte("{type:'info', msg:'Success!'}"))
}
Co-incidentally to provide output via a different method you use something like;
serv.ResponseBuilder().Created("http://localhost:8787/orders-service/items/"+string(i.Id))
Which I found at http://code.google.com/p/gorest/