本文整理匯總了Golang中github.com/mondough/mercury.Request.Response方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Response方法的具體用法?Golang Request.Response怎麽用?Golang Request.Response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mondough/mercury.Request
的用法示例。
在下文中一共展示了Request.Response方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handler
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
}
示例2: ErrorResponse
// 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
}