Codebase list golang-github-go-kit-kit / 45cd825
transport/grpc, examples/addsvc: adapt context Peter Bourgon 7 years ago
5 changed file(s) with 20 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
66 "context"
77
88 stdopentracing "github.com/opentracing/opentracing-go"
9 oldcontext "golang.org/x/net/context"
910
1011 "github.com/go-kit/kit/examples/addsvc/pb"
1112 "github.com/go-kit/kit/log"
4142 concat grpctransport.Handler
4243 }
4344
44 func (s *grpcServer) Sum(ctx context.Context, req *pb.SumRequest) (*pb.SumReply, error) {
45 func (s *grpcServer) Sum(ctx oldcontext.Context, req *pb.SumRequest) (*pb.SumReply, error) {
4546 _, rep, err := s.sum.ServeGRPC(ctx, req)
4647 if err != nil {
4748 return nil, err
4950 return rep.(*pb.SumReply), nil
5051 }
5152
52 func (s *grpcServer) Concat(ctx context.Context, req *pb.ConcatRequest) (*pb.ConcatReply, error) {
53 func (s *grpcServer) Concat(ctx oldcontext.Context, req *pb.ConcatRequest) (*pb.ConcatReply, error) {
5354 _, rep, err := s.concat.ServeGRPC(ctx, req)
5455 if err != nil {
5556 return nil, err
00 package grpc
11
22 import (
3 "context"
34 "fmt"
45 "reflect"
56 "strings"
67
7 "golang.org/x/net/context"
88 "google.golang.org/grpc"
99 "google.golang.org/grpc/metadata"
1010
00 package grpc
11
22 import (
3 "golang.org/x/net/context"
3 "context"
44 )
55
66 // DecodeRequestFunc extracts a user-domain request object from a gRPC request.
77 // It's designed to be used in gRPC servers, for server-side endpoints. One
8 // straightforward DecodeRequestFunc could be something that
9 // decodes from the gRPC request message to the concrete request type.
8 // straightforward DecodeRequestFunc could be something that decodes from the
9 // gRPC request message to the concrete request type.
1010 type DecodeRequestFunc func(context.Context, interface{}) (request interface{}, err error)
1111
1212 // EncodeRequestFunc encodes the passed request object into the gRPC request
13 // object. It's designed to be used in gRPC clients, for client-side
14 // endpoints. One straightforward EncodeRequestFunc could something that
15 // encodes the object directly to the gRPC request message.
13 // object. It's designed to be used in gRPC clients, for client-side endpoints.
14 // One straightforward EncodeRequestFunc could something that encodes the object
15 // directly to the gRPC request message.
1616 type EncodeRequestFunc func(context.Context, interface{}) (request interface{}, err error)
1717
1818 // EncodeResponseFunc encodes the passed response object to the gRPC response
19 // message. It's designed to be used in gRPC servers, for server-side
20 // endpoints. One straightforward EncodeResponseFunc could be something that
21 // encodes the object directly to the gRPC response message.
19 // message. It's designed to be used in gRPC servers, for server-side endpoints.
20 // One straightforward EncodeResponseFunc could be something that encodes the
21 // object directly to the gRPC response message.
2222 type EncodeResponseFunc func(context.Context, interface{}) (response interface{}, err error)
2323
2424 // DecodeResponseFunc extracts a user-domain response object from a gRPC
00 package grpc
11
22 import (
3 "context"
34 "encoding/base64"
45 "strings"
56
6 "golang.org/x/net/context"
77 "google.golang.org/grpc/metadata"
88 )
99
00 package grpc
11
22 import (
3 "golang.org/x/net/context"
3 "context"
4
5 oldcontext "golang.org/x/net/context"
46 "google.golang.org/grpc/metadata"
57
68 "github.com/go-kit/kit/endpoint"
79 "github.com/go-kit/kit/log"
810 )
911
10 // Handler which should be called from the grpc binding of the service
12 // Handler which should be called from the gRPC binding of the service
1113 // implementation. The incoming request parameter, and returned response
1214 // parameter, are both gRPC types, not user-domain.
1315 type Handler interface {
14 ServeGRPC(ctx context.Context, request interface{}) (context.Context, interface{}, error)
16 ServeGRPC(ctx oldcontext.Context, request interface{}) (oldcontext.Context, interface{}, error)
1517 }
1618
1719 // Server wraps an endpoint and implements grpc.Handler.
7274 }
7375
7476 // ServeGRPC implements the Handler interface.
75 func (s Server) ServeGRPC(grpcCtx context.Context, req interface{}) (context.Context, interface{}, error) {
77 func (s Server) ServeGRPC(grpcCtx oldcontext.Context, req interface{}) (oldcontext.Context, interface{}, error) {
7678 ctx := s.ctx
7779
7880 // Retrieve gRPC metadata.