本文整理匯總了Golang中github.com/mondough/mercury.Request.Id方法的典型用法代碼示例。如果您正苦於以下問題:Golang Request.Id方法的具體用法?Golang Request.Id怎麽用?Golang Request.Id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mondough/mercury.Request
的用法示例。
在下文中一共展示了Request.Id方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ProcessServerRequest
func (m requestTreeMiddleware) ProcessServerRequest(req mercury.Request) (mercury.Request, mercury.Response) {
req.SetContext(context.WithValue(req.Context(), reqIdCtxKey, req.Id()))
if v := req.Headers()[parentIdHeader]; v != "" {
req.SetContext(context.WithValue(req.Context(), parentIdCtxKey, v))
}
// Set the current service and endpoint into the context
req.SetContext(context.WithValue(req.Context(), currentServiceHeader, req.Service()))
req.SetContext(context.WithValue(req.Context(), currentEndpointHeader, req.Endpoint()))
// Set the originator into the context
req.SetContext(context.WithValue(req.Context(), originServiceHeader, req.Headers()[originServiceHeader]))
req.SetContext(context.WithValue(req.Context(), originEndpointHeader, req.Headers()[originEndpointHeader]))
return req, nil
}
示例2: old2NewRequest
func old2NewRequest(oldReq mercury.Request) typhon.Request {
ep := oldReq.Endpoint()
if !strings.HasPrefix(ep, "/") {
ep = "/" + ep
}
v := typhon.Request{
Context: oldReq.Context(),
Request: http.Request{
Method: "POST",
URL: &url.URL{
Scheme: "http",
Host: oldReq.Service(),
Path: ep},
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: toHeader(oldReq.Headers()),
Host: oldReq.Service(),
Body: ioutil.NopCloser(bytes.NewReader(oldReq.Payload())),
ContentLength: int64(len(oldReq.Payload()))}}
v.Header.Set(legacyIdHeader, oldReq.Id())
return v
}
示例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) (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
}