本文整理汇总了Golang中go/uber/org/yarpc.ReqMeta类的典型用法代码示例。如果您正苦于以下问题:Golang ReqMeta类的具体用法?Golang ReqMeta怎么用?Golang ReqMeta使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReqMeta类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Handle
func (h *multiHopHandler) Handle(ctx context.Context, reqMeta yarpc.ReqMeta, body interface{}) (interface{}, yarpc.ResMeta, error) {
if h.phoneClient == nil {
panic("call SetClient() and SetTransport() first")
}
assertBaggageMatches(ctx, h.t, h.wantBaggage)
span := opentracing.SpanFromContext(ctx)
for key, value := range h.addBaggage {
span.SetBaggageItem(key, value)
}
ctx = opentracing.ContextWithSpan(ctx, span)
var resp js.RawMessage
phoneResMeta, err := h.phoneClient.Call(
ctx,
yarpc.NewReqMeta().Procedure("phone").Headers(reqMeta.Headers()),
&server.PhoneRequest{
Service: "ctxclient",
Procedure: h.phoneCallTo,
Transport: h.phoneCallTransport,
Body: &js.RawMessage{'{', '}'},
}, &resp)
resMeta := yarpc.NewResMeta().Headers(phoneResMeta.Headers())
return map[string]interface{}{}, resMeta, err
}
示例2: Phone
// Phone implements the phone procedure
func Phone(ctx context.Context, reqMeta yarpc.ReqMeta, body *PhoneRequest) (*PhoneResponse, yarpc.ResMeta, error) {
var outbound transport.UnaryOutbound
switch {
case body.Transport.HTTP != nil:
t := body.Transport.HTTP
url := fmt.Sprintf("http://%s:%d", t.Host, t.Port)
outbound = ht.NewOutbound(url)
case body.Transport.TChannel != nil:
t := body.Transport.TChannel
hostport := fmt.Sprintf("%s:%d", t.Host, t.Port)
ch, err := tchannel.NewChannel("yarpc-test-client", nil)
if err != nil {
return nil, nil, fmt.Errorf("failed to build TChannel: %v", err)
}
outbound = tch.NewOutbound(ch, tch.HostPort(hostport))
default:
return nil, nil, fmt.Errorf("unconfigured transport")
}
if err := outbound.Start(transport.NoDeps); err != nil {
return nil, nil, err
}
defer outbound.Stop()
// TODO use reqMeta.Service for caller
client := json.New(channel.MultiOutbound("yarpc-test", body.Service, transport.Outbounds{
Unary: outbound,
}))
resBody := PhoneResponse{
Service: "yarpc-test", // TODO use reqMeta.Service
Procedure: reqMeta.Procedure(),
}
ctx, cancel := context.WithTimeout(ctx, 500*time.Millisecond)
defer cancel()
_, err := client.Call(
ctx,
yarpc.NewReqMeta().Procedure(body.Procedure),
body.Body,
&resBody.Body)
if err != nil {
return nil, nil, err
}
return &resBody, nil, nil
}
示例3: resMetaFromReqMeta
func resMetaFromReqMeta(reqMeta yarpc.ReqMeta) yarpc.ResMeta {
return yarpc.NewResMeta().Headers(reqMeta.Headers())
}
示例4: Echo
func (h helloHandler) Echo(ctx context.Context, reqMeta yarpc.ReqMeta, e *echo.EchoRequest) (*echo.EchoResponse, yarpc.ResMeta, error) {
return &echo.EchoResponse{Message: e.Message, Count: e.Count + 1},
yarpc.NewResMeta().Headers(reqMeta.Headers()),
nil
}
示例5: yarpcEcho
func yarpcEcho(ctx context.Context, reqMeta yarpc.ReqMeta, body []byte) ([]byte, yarpc.ResMeta, error) {
return body, yarpc.NewResMeta().Headers(reqMeta.Headers()), nil
}
示例6: Echo
// Echo endpoint for the Echo service.
func (EchoThrift) Echo(ctx context.Context, reqMeta yarpc.ReqMeta, ping *echo.Ping) (*echo.Pong, yarpc.ResMeta, error) {
return &echo.Pong{Boop: ping.Beep}, yarpc.NewResMeta().Headers(reqMeta.Headers()), nil
}
示例7: EchoJSON
// EchoJSON implements the echo procedure.
func EchoJSON(ctx context.Context, reqMeta yarpc.ReqMeta, body map[string]interface{}) (map[string]interface{}, yarpc.ResMeta, error) {
return body, yarpc.NewResMeta().Headers(reqMeta.Headers()), nil
}