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 }
// 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 }
func resMetaFromReqMeta(reqMeta yarpc.ReqMeta) yarpc.ResMeta { return yarpc.NewResMeta().Headers(reqMeta.Headers()) }
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 }
func yarpcEcho(ctx context.Context, reqMeta yarpc.ReqMeta, body []byte) ([]byte, yarpc.ResMeta, error) { return body, yarpc.NewResMeta().Headers(reqMeta.Headers()), nil }
// 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 }
// 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 }
func (h *singleHopHandler) Handle(ctx context.Context, reqMeta yarpc.ReqMeta, body interface{}) (interface{}, yarpc.ResMeta, error) { assertBaggageMatches(ctx, h.t, h.wantBaggage) resMeta := yarpc.NewResMeta().Headers(reqMeta.Headers()) return map[string]interface{}{}, resMeta, nil }