Package list golang-github-go-kit-kit / fa1983f
Respond to review comments Ben Sigelman 5 years ago
6 changed file(s) with 22 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
1212 "github.com/opentracing/opentracing-go"
1313 )
1414
15 // SumEndpointFactory transforms GRPC host:port strings into Endpoints that call the Sum method on a GRPC server
15 // MakeSumEndpointFactory returns a loadbalancer.Factory that transforms GRPC
16 // host:port strings into Endpoints that call the Sum method on a GRPC server
1617 // at that address.
17 func NewSumEndpointFactory(tracer opentracing.Tracer) loadbalancer.Factory {
18 func MakeSumEndpointFactory(tracer opentracing.Tracer) loadbalancer.Factory {
1819 return func(instance string) (endpoint.Endpoint, io.Closer, error) {
1920 cc, err := grpc.Dial(instance, grpc.WithInsecure())
2021 return grpctransport.NewClient(
2930 }
3031 }
3132
32 // ConcatEndpointFactory transforms GRPC host:port strings into Endpoints that call the Concat method on a GRPC server
33 // at that address.
34 func NewConcatEndpointFactory(tracer opentracing.Tracer) loadbalancer.Factory {
33 // MakeConcatEndpointFactory returns a loadbalancer.Factory that transforms
34 // GRPC host:port strings into Endpoints that call the Concat method on a GRPC
35 // server at that address.
36 func MakeConcatEndpointFactory(tracer opentracing.Tracer) loadbalancer.Factory {
3537 return func(instance string) (endpoint.Endpoint, io.Closer, error) {
3638 cc, err := grpc.Dial(instance, grpc.WithInsecure())
3739 return grpctransport.NewClient(
1111 "github.com/opentracing/opentracing-go"
1212 )
1313
14 // SumEndpointFactory generates a Factory that transforms an http url into an
15 // Endpoint.
14 // MakeSumEndpointFactory generates a Factory that transforms an http url into
15 // an Endpoint.
1616 //
1717 // The path of the url is reset to /sum.
18 func NewSumEndpointFactory(tracer opentracing.Tracer) loadbalancer.Factory {
18 func MakeSumEndpointFactory(tracer opentracing.Tracer) loadbalancer.Factory {
1919 return func(instance string) (endpoint.Endpoint, io.Closer, error) {
2020 sumURL, err := url.Parse(instance)
2121 if err != nil {
3636 }
3737 }
3838
39 // NewConcatEndpointFactory generates a Factory that transforms an http url
39 // MakeConcatEndpointFactory generates a Factory that transforms an http url
4040 // into an Endpoint.
4141 //
4242 // The path of the url is reset to /concat.
43 func NewConcatEndpointFactory(tracer opentracing.Tracer) loadbalancer.Factory {
43 func MakeConcatEndpointFactory(tracer opentracing.Tracer) loadbalancer.Factory {
4444 return func(instance string) (endpoint.Endpoint, io.Closer, error) {
4545 concatURL, err := url.Parse(instance)
4646 if err != nil {
8484 switch *transport {
8585 case "grpc":
8686 instances = strings.Split(*grpcAddrs, ",")
87 sumFactory = grpcclient.NewSumEndpointFactory(tracer)
88 concatFactory = grpcclient.NewConcatEndpointFactory(tracer)
87 sumFactory = grpcclient.MakeSumEndpointFactory(tracer)
88 concatFactory = grpcclient.MakeConcatEndpointFactory(tracer)
8989
9090 case "httpjson":
9191 instances = strings.Split(*httpAddrs, ",")
9494 instances[i] = "http://" + rawurl
9595 }
9696 }
97 sumFactory = httpjsonclient.NewSumEndpointFactory(tracer)
98 concatFactory = httpjsonclient.NewConcatEndpointFactory(tracer)
97 sumFactory = httpjsonclient.MakeSumEndpointFactory(tracer)
98 concatFactory = httpjsonclient.MakeConcatEndpointFactory(tracer)
9999
100100 case "netrpc":
101101 instances = strings.Split(*netrpcAddrs, ",")
99
1010 type pureAddService struct{}
1111
12 func (pureAddService) Sum(a, b int) int {
13 return a + b
14 }
12 func (pureAddService) Sum(a, b int) int { return a + b }
1513
1614 func (pureAddService) Concat(a, b string) string { return a + b }
1715
7777 factory loadbalancer.Factory
7878 }{
7979 "addsvc": {
80 {path: "/api/addsvc/concat", factory: grpc.NewConcatEndpointFactory(opentracing.GlobalTracer())},
81 {path: "/api/addsvc/sum", factory: grpc.NewSumEndpointFactory(opentracing.GlobalTracer())},
80 {path: "/api/addsvc/concat", factory: grpc.MakeConcatEndpointFactory(opentracing.GlobalTracer())},
81 {path: "/api/addsvc/sum", factory: grpc.MakeSumEndpointFactory(opentracing.GlobalTracer())},
8282 },
8383 "stringsvc": {
8484 {path: "/api/stringsvc/uppercase", factory: httpFactory(ctx, "GET", "uppercase/")},
22 import (
33 "github.com/go-kit/kit/endpoint"
44 "github.com/opentracing/opentracing-go"
5 otext "github.com/opentracing/opentracing-go/ext"
56 "golang.org/x/net/context"
67 )
78
2021 } else {
2122 serverSpan.SetOperationName(operationName)
2223 }
23 serverSpan.SetTag("span.kind", "server")
24 otext.SpanKind.Set(serverSpan, otext.SpanKindRPCServer)
2425 ctx = opentracing.ContextWithSpan(ctx, serverSpan)
2526 defer serverSpan.Finish()
2627 return next(ctx, request)
3839 OperationName: operationName,
3940 Parent: parentSpan, // may be nil
4041 })
41 clientSpan.SetTag("span.kind", "client")
42 otext.SpanKind.Set(clientSpan, otext.SpanKindRPCClient)
4243 ctx = opentracing.ContextWithSpan(ctx, clientSpan)
4344 defer clientSpan.Finish()
4445 return next(ctx, request)