當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Request.Body方法代碼示例

本文整理匯總了Golang中github.com/mondough/mercury.Request.Body方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Body方法的具體用法?Golang Request.Body怎麽用?Golang Request.Body使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/mondough/mercury.Request的用法示例。


在下文中一共展示了Request.Body方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
開發者ID:yonglehou,項目名稱:go-micro,代碼行數:7,代碼來源:server.go

示例2: Handle

// Handle takes an inbound Request, unmarshals it, dispatches it to the handler, and serialises the result as a
// Response. Note that the response may be nil.
func (e Endpoint) Handle(req mercury.Request) (rsp mercury.Response, err error) {
	// Unmarshal the request body (unless there already is one)
	if req.Body() == nil && e.Request != nil {
		if um := e.unmarshaler(req); um != nil {
			if werr := terrors.Wrap(um.UnmarshalPayload(req), nil); werr != nil {
				log.Warnf("[Mercury:Server] Cannot unmarshal request payload: %v", werr)
				terr := werr.(*terrors.Error)
				terr.Code = terrors.ErrBadRequest
				rsp, err = nil, terr
				return
			}
		}
	}

	defer func() {
		if v := recover(); v != nil {
			traceVerbose := make([]byte, 1024)
			runtime.Stack(traceVerbose, true)
			log.Criticalf("[Mercury:Server] Recovered from handler panic for request %s:\n%v\n%s", req.Id(), v,
				string(traceVerbose))
			rsp, err = nil, terrors.InternalService("panic", fmt.Sprintf("Panic in handler %s:\n%s", req.Endpoint(),
				string(traceVerbose)), nil)
		}
	}()
	rsp, err = e.Handler(req)
	return
}
開發者ID:robmurtha,項目名稱:mercury,代碼行數:29,代碼來源:endpoint.go

示例3: Handle

// Handle takes an inbound Request, unmarshals it, dispatches it to the handler, and serialises the result as a
// Response. Note that the response may be nil.
func (e Endpoint) Handle(req mercury.Request) (mercury.Response, error) {
	// Unmarshal the request body (unless there already is one)
	if req.Body() == nil && e.Request != nil {
		if um := e.unmarshaler(req); um != nil {
			if werr := terrors.Wrap(um.UnmarshalPayload(req), nil); werr != nil {
				log.Warn(req, "[Mercury:Server] Cannot unmarshal request payload: %v", werr)
				terr := werr.(*terrors.Error)
				terr.Code = terrors.ErrBadRequest
				return nil, terr
			}
		}
	}

	return e.Handler(req)
}
開發者ID:mondough,項目名稱:mercury,代碼行數:17,代碼來源:endpoint.go


注:本文中的github.com/mondough/mercury.Request.Body方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。