Преглед изворни кода

[dev] Set plugins=grpc when generating testdata protos.

Change-Id: I57a5edf2e9e0c4f70efc4d4fa97b79cd97925757
Damien Neil пре 8 година
родитељ
комит
f7e61e16d5

+ 1 - 1
protoc-gen-go/golden_test.go

@@ -56,7 +56,7 @@ func TestGolden(t *testing.T) {
 			"protoc",
 			"--plugin=protoc-gen-go="+os.Args[0],
 			"-Itestdata",
-			"--go_out="+workdir,
+			"--go_out=plugins=grpc:"+workdir,
 		)
 		cmd.Args = append(cmd.Args, sources...)
 		cmd.Env = append(os.Environ(), "RUN_AS_PROTOC_GEN_GO=1")

+ 84 - 0
protoc-gen-go/testdata/deprecated/deprecated.pb.go

@@ -19,6 +19,11 @@ import proto "github.com/golang/protobuf/proto"
 import fmt "fmt"
 import math "math"
 
+import (
+	context "golang.org/x/net/context"
+	grpc "google.golang.org/grpc"
+)
+
 // Reference imports to suppress errors if they are not otherwise used.
 var _ = proto.Marshal
 var _ = fmt.Errorf
@@ -125,6 +130,85 @@ func init() {
 	proto.RegisterEnum("deprecated.DeprecatedEnum", DeprecatedEnum_name, DeprecatedEnum_value)
 }
 
+// Reference imports to suppress errors if they are not otherwise used.
+var _ context.Context
+var _ grpc.ClientConn
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the grpc package it is being compiled against.
+const _ = grpc.SupportPackageIsVersion4
+
+// Client API for DeprecatedService service
+
+// Deprecated: Do not use.
+type DeprecatedServiceClient interface {
+	// DeprecatedCall takes a DeprecatedRequest and returns a DeprecatedResponse.
+	DeprecatedCall(ctx context.Context, in *DeprecatedRequest, opts ...grpc.CallOption) (*DeprecatedResponse, error)
+}
+
+type deprecatedServiceClient struct {
+	cc *grpc.ClientConn
+}
+
+// Deprecated: Do not use.
+func NewDeprecatedServiceClient(cc *grpc.ClientConn) DeprecatedServiceClient {
+	return &deprecatedServiceClient{cc}
+}
+
+// Deprecated: Do not use.
+func (c *deprecatedServiceClient) DeprecatedCall(ctx context.Context, in *DeprecatedRequest, opts ...grpc.CallOption) (*DeprecatedResponse, error) {
+	out := new(DeprecatedResponse)
+	err := grpc.Invoke(ctx, "/deprecated.DeprecatedService/DeprecatedCall", in, out, c.cc, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+// Server API for DeprecatedService service
+
+// Deprecated: Do not use.
+type DeprecatedServiceServer interface {
+	// DeprecatedCall takes a DeprecatedRequest and returns a DeprecatedResponse.
+	DeprecatedCall(context.Context, *DeprecatedRequest) (*DeprecatedResponse, error)
+}
+
+// Deprecated: Do not use.
+func RegisterDeprecatedServiceServer(s *grpc.Server, srv DeprecatedServiceServer) {
+	s.RegisterService(&_DeprecatedService_serviceDesc, srv)
+}
+
+func _DeprecatedService_DeprecatedCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(DeprecatedRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(DeprecatedServiceServer).DeprecatedCall(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/deprecated.DeprecatedService/DeprecatedCall",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(DeprecatedServiceServer).DeprecatedCall(ctx, req.(*DeprecatedRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+var _DeprecatedService_serviceDesc = grpc.ServiceDesc{
+	ServiceName: "deprecated.DeprecatedService",
+	HandlerType: (*DeprecatedServiceServer)(nil),
+	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "DeprecatedCall",
+			Handler:    _DeprecatedService_DeprecatedCall_Handler,
+		},
+	},
+	Streams:  []grpc.StreamDesc{},
+	Metadata: "deprecated/deprecated.proto",
+}
+
 func init() { proto.RegisterFile("deprecated/deprecated.proto", fileDescriptor0) }
 
 var fileDescriptor0 = []byte{

+ 276 - 0
protoc-gen-go/testdata/grpc/grpc.pb.go

@@ -19,6 +19,11 @@ import proto "github.com/golang/protobuf/proto"
 import fmt "fmt"
 import math "math"
 
+import (
+	context "golang.org/x/net/context"
+	grpc "google.golang.org/grpc"
+)
+
 // Reference imports to suppress errors if they are not otherwise used.
 var _ = proto.Marshal
 var _ = fmt.Errorf
@@ -149,6 +154,277 @@ func init() {
 	proto.RegisterType((*StreamMsg2)(nil), "grpc.testing.StreamMsg2")
 }
 
+// Reference imports to suppress errors if they are not otherwise used.
+var _ context.Context
+var _ grpc.ClientConn
+
+// This is a compile-time assertion to ensure that this generated file
+// is compatible with the grpc package it is being compiled against.
+const _ = grpc.SupportPackageIsVersion4
+
+// Client API for Test service
+
+type TestClient interface {
+	UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error)
+	// This RPC streams from the server only.
+	Downstream(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (Test_DownstreamClient, error)
+	// This RPC streams from the client.
+	Upstream(ctx context.Context, opts ...grpc.CallOption) (Test_UpstreamClient, error)
+	// This one streams in both directions.
+	Bidi(ctx context.Context, opts ...grpc.CallOption) (Test_BidiClient, error)
+}
+
+type testClient struct {
+	cc *grpc.ClientConn
+}
+
+func NewTestClient(cc *grpc.ClientConn) TestClient {
+	return &testClient{cc}
+}
+
+func (c *testClient) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error) {
+	out := new(SimpleResponse)
+	err := grpc.Invoke(ctx, "/grpc.testing.Test/UnaryCall", in, out, c.cc, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *testClient) Downstream(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (Test_DownstreamClient, error) {
+	stream, err := grpc.NewClientStream(ctx, &_Test_serviceDesc.Streams[0], c.cc, "/grpc.testing.Test/Downstream", opts...)
+	if err != nil {
+		return nil, err
+	}
+	x := &testDownstreamClient{stream}
+	if err := x.ClientStream.SendMsg(in); err != nil {
+		return nil, err
+	}
+	if err := x.ClientStream.CloseSend(); err != nil {
+		return nil, err
+	}
+	return x, nil
+}
+
+type Test_DownstreamClient interface {
+	Recv() (*StreamMsg, error)
+	grpc.ClientStream
+}
+
+type testDownstreamClient struct {
+	grpc.ClientStream
+}
+
+func (x *testDownstreamClient) Recv() (*StreamMsg, error) {
+	m := new(StreamMsg)
+	if err := x.ClientStream.RecvMsg(m); err != nil {
+		return nil, err
+	}
+	return m, nil
+}
+
+func (c *testClient) Upstream(ctx context.Context, opts ...grpc.CallOption) (Test_UpstreamClient, error) {
+	stream, err := grpc.NewClientStream(ctx, &_Test_serviceDesc.Streams[1], c.cc, "/grpc.testing.Test/Upstream", opts...)
+	if err != nil {
+		return nil, err
+	}
+	x := &testUpstreamClient{stream}
+	return x, nil
+}
+
+type Test_UpstreamClient interface {
+	Send(*StreamMsg) error
+	CloseAndRecv() (*SimpleResponse, error)
+	grpc.ClientStream
+}
+
+type testUpstreamClient struct {
+	grpc.ClientStream
+}
+
+func (x *testUpstreamClient) Send(m *StreamMsg) error {
+	return x.ClientStream.SendMsg(m)
+}
+
+func (x *testUpstreamClient) CloseAndRecv() (*SimpleResponse, error) {
+	if err := x.ClientStream.CloseSend(); err != nil {
+		return nil, err
+	}
+	m := new(SimpleResponse)
+	if err := x.ClientStream.RecvMsg(m); err != nil {
+		return nil, err
+	}
+	return m, nil
+}
+
+func (c *testClient) Bidi(ctx context.Context, opts ...grpc.CallOption) (Test_BidiClient, error) {
+	stream, err := grpc.NewClientStream(ctx, &_Test_serviceDesc.Streams[2], c.cc, "/grpc.testing.Test/Bidi", opts...)
+	if err != nil {
+		return nil, err
+	}
+	x := &testBidiClient{stream}
+	return x, nil
+}
+
+type Test_BidiClient interface {
+	Send(*StreamMsg) error
+	Recv() (*StreamMsg2, error)
+	grpc.ClientStream
+}
+
+type testBidiClient struct {
+	grpc.ClientStream
+}
+
+func (x *testBidiClient) Send(m *StreamMsg) error {
+	return x.ClientStream.SendMsg(m)
+}
+
+func (x *testBidiClient) Recv() (*StreamMsg2, error) {
+	m := new(StreamMsg2)
+	if err := x.ClientStream.RecvMsg(m); err != nil {
+		return nil, err
+	}
+	return m, nil
+}
+
+// Server API for Test service
+
+type TestServer interface {
+	UnaryCall(context.Context, *SimpleRequest) (*SimpleResponse, error)
+	// This RPC streams from the server only.
+	Downstream(*SimpleRequest, Test_DownstreamServer) error
+	// This RPC streams from the client.
+	Upstream(Test_UpstreamServer) error
+	// This one streams in both directions.
+	Bidi(Test_BidiServer) error
+}
+
+func RegisterTestServer(s *grpc.Server, srv TestServer) {
+	s.RegisterService(&_Test_serviceDesc, srv)
+}
+
+func _Test_UnaryCall_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(SimpleRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(TestServer).UnaryCall(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/grpc.testing.Test/UnaryCall",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(TestServer).UnaryCall(ctx, req.(*SimpleRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Test_Downstream_Handler(srv interface{}, stream grpc.ServerStream) error {
+	m := new(SimpleRequest)
+	if err := stream.RecvMsg(m); err != nil {
+		return err
+	}
+	return srv.(TestServer).Downstream(m, &testDownstreamServer{stream})
+}
+
+type Test_DownstreamServer interface {
+	Send(*StreamMsg) error
+	grpc.ServerStream
+}
+
+type testDownstreamServer struct {
+	grpc.ServerStream
+}
+
+func (x *testDownstreamServer) Send(m *StreamMsg) error {
+	return x.ServerStream.SendMsg(m)
+}
+
+func _Test_Upstream_Handler(srv interface{}, stream grpc.ServerStream) error {
+	return srv.(TestServer).Upstream(&testUpstreamServer{stream})
+}
+
+type Test_UpstreamServer interface {
+	SendAndClose(*SimpleResponse) error
+	Recv() (*StreamMsg, error)
+	grpc.ServerStream
+}
+
+type testUpstreamServer struct {
+	grpc.ServerStream
+}
+
+func (x *testUpstreamServer) SendAndClose(m *SimpleResponse) error {
+	return x.ServerStream.SendMsg(m)
+}
+
+func (x *testUpstreamServer) Recv() (*StreamMsg, error) {
+	m := new(StreamMsg)
+	if err := x.ServerStream.RecvMsg(m); err != nil {
+		return nil, err
+	}
+	return m, nil
+}
+
+func _Test_Bidi_Handler(srv interface{}, stream grpc.ServerStream) error {
+	return srv.(TestServer).Bidi(&testBidiServer{stream})
+}
+
+type Test_BidiServer interface {
+	Send(*StreamMsg2) error
+	Recv() (*StreamMsg, error)
+	grpc.ServerStream
+}
+
+type testBidiServer struct {
+	grpc.ServerStream
+}
+
+func (x *testBidiServer) Send(m *StreamMsg2) error {
+	return x.ServerStream.SendMsg(m)
+}
+
+func (x *testBidiServer) Recv() (*StreamMsg, error) {
+	m := new(StreamMsg)
+	if err := x.ServerStream.RecvMsg(m); err != nil {
+		return nil, err
+	}
+	return m, nil
+}
+
+var _Test_serviceDesc = grpc.ServiceDesc{
+	ServiceName: "grpc.testing.Test",
+	HandlerType: (*TestServer)(nil),
+	Methods: []grpc.MethodDesc{
+		{
+			MethodName: "UnaryCall",
+			Handler:    _Test_UnaryCall_Handler,
+		},
+	},
+	Streams: []grpc.StreamDesc{
+		{
+			StreamName:    "Downstream",
+			Handler:       _Test_Downstream_Handler,
+			ServerStreams: true,
+		},
+		{
+			StreamName:    "Upstream",
+			Handler:       _Test_Upstream_Handler,
+			ClientStreams: true,
+		},
+		{
+			StreamName:    "Bidi",
+			Handler:       _Test_Bidi_Handler,
+			ServerStreams: true,
+			ClientStreams: true,
+		},
+	},
+	Metadata: "grpc/grpc.proto",
+}
+
 func init() { proto.RegisterFile("grpc/grpc.proto", fileDescriptor0) }
 
 var fileDescriptor0 = []byte{