Skip to content

Commit

Permalink
Merge pull request go-kit#585 from basvanbeek/master
Browse files Browse the repository at this point in the history
updated thrift to latest Go library adding support for context
  • Loading branch information
peterbourgon authored Jul 26, 2017
2 parents c775377 + 2b71427 commit 192d9cf
Show file tree
Hide file tree
Showing 8 changed files with 1,234 additions and 1,232 deletions.
3 changes: 1 addition & 2 deletions addsvc/cmd/addsvc/addsvc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"flag"
"fmt"
"net"
Expand Down Expand Up @@ -140,7 +139,7 @@ func main() {
endpoints = addendpoint.New(service, logger, duration, tracer)
httpHandler = addtransport.NewHTTPHandler(endpoints, tracer, logger)
grpcServer = addtransport.NewGRPCServer(endpoints, tracer, logger)
thriftServer = addtransport.NewThriftServer(context.Background(), endpoints)
thriftServer = addtransport.NewThriftServer(endpoints)
)

// Now we're to the part of the func main where we want to start actually
Expand Down
15 changes: 7 additions & 8 deletions addsvc/pkg/addtransport/thrift.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,25 @@ type thriftServer struct {
}

// NewThriftServer makes a set of endpoints available as a Thrift service.
func NewThriftServer(ctx context.Context, endpoints addendpoint.Set) addthrift.AddService {
func NewThriftServer(endpoints addendpoint.Set) addthrift.AddService {
return &thriftServer{
ctx: ctx,
endpoints: endpoints,
}
}

func (s *thriftServer) Sum(a int64, b int64) (*addthrift.SumReply, error) {
func (s *thriftServer) Sum(ctx context.Context, a int64, b int64) (*addthrift.SumReply, error) {
request := addendpoint.SumRequest{A: int(a), B: int(b)}
response, err := s.endpoints.SumEndpoint(s.ctx, request)
response, err := s.endpoints.SumEndpoint(ctx, request)
if err != nil {
return nil, err
}
resp := response.(addendpoint.SumResponse)
return &addthrift.SumReply{Value: int64(resp.V), Err: err2str(resp.Err)}, nil
}

func (s *thriftServer) Concat(a string, b string) (*addthrift.ConcatReply, error) {
func (s *thriftServer) Concat(ctx context.Context, a string, b string) (*addthrift.ConcatReply, error) {
request := addendpoint.ConcatRequest{A: a, B: b}
response, err := s.endpoints.ConcatEndpoint(s.ctx, request)
response, err := s.endpoints.ConcatEndpoint(ctx, request)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -100,7 +99,7 @@ func NewThriftClient(client *addthrift.AddServiceClient) addservice.Service {
func MakeThriftSumEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(addendpoint.SumRequest)
reply, err := client.Sum(int64(req.A), int64(req.B))
reply, err := client.Sum(ctx, int64(req.A), int64(req.B))
if err == addservice.ErrIntOverflow {
return nil, err // special case; see comment on ErrIntOverflow
}
Expand All @@ -114,7 +113,7 @@ func MakeThriftSumEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint
func MakeThriftConcatEndpoint(client *addthrift.AddServiceClient) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(addendpoint.ConcatRequest)
reply, err := client.Concat(req.A, req.B)
reply, err := client.Concat(ctx, req.A, req.B)
return addendpoint.ConcatResponse{V: reply.Value, Err: err}, nil
}
}
7 changes: 7 additions & 0 deletions addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

292 changes: 147 additions & 145 deletions addsvc/thrift/gen-go/addsvc/add_service-remote/add_service-remote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 192d9cf

Please sign in to comment.