Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated thrift to latest Go library adding support for context #585

Merged
merged 1 commit into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/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 examples/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 examples/addsvc/thrift/gen-go/addsvc/GoUnusedProtection__.go

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

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

Loading