func handler(req mercury.Request) (mercury.Response, error) { request := req.Body().(*hello.Request) rsp := req.Response(&hello.Response{ Msg: "Hey " + request.Name, }) return rsp, nil }
// ErrorResponse constructs a response for the given request, with the given error as its contents. Mercury clients // know how to unmarshal these errors. func ErrorResponse(req mercury.Request, err error) mercury.Response { rsp := req.Response(nil) var terr *terrors.Error if err != nil { terr = terrors.Wrap(err, nil).(*terrors.Error) } rsp.SetBody(terrors.Marshal(terr)) if err := tmsg.ProtoMarshaler().MarshalBody(rsp); err != nil { log.Errorf("[Mercury:Server] Failed to marshal error response: %v", err) return nil // Not much we can do here } rsp.SetIsError(true) return rsp }