67d51da37b6e03319d7705a243cb4f55923bfa6b.svn-base 861 B

123456789101112131415161718192021222324252627282930313233
  1. package main
  2. import (
  3. "context"
  4. "github.com/go-kit/kit/transport/grpc"
  5. "github.com/longjoy/micro-go-course/section35/zipkin-kit/client"
  6. "github.com/longjoy/micro-go-course/section35/zipkin-kit/pb"
  7. "github.com/longjoy/micro-go-course/section35/zipkin-kit/string-service/endpoint"
  8. )
  9. type grpcServer struct {
  10. diff grpc.Handler
  11. }
  12. func (s *grpcServer) Diff(ctx context.Context, r *pb.StringRequest) (*pb.StringResponse, error) {
  13. _, resp, err := s.diff.ServeGRPC(ctx, r)
  14. if err != nil {
  15. return nil, err
  16. }
  17. return resp.(*pb.StringResponse), nil
  18. }
  19. func NewGRPCServer(ctx context.Context, endpoints endpoint.StringEndpoints, serverTracer grpc.ServerOption) pb.StringServiceServer {
  20. return &grpcServer{
  21. diff: grpc.NewServer(
  22. endpoints.StringEndpoint,
  23. client.DecodeGRPCStringRequest,
  24. client.EncodeGRPCStringResponse,
  25. serverTracer,
  26. ),
  27. }
  28. }