From 60b329df360783061bd1ca43028b47689238e713 Mon Sep 17 00:00:00 2001 From: Ahmad Muzakki Date: Tue, 17 Sep 2019 18:00:37 +0700 Subject: [PATCH] address review --- example/simple/client/main.go | 2 +- example/simple/simple.pb.go | 76 +++++++++---------- example/simple/simple.proto | 4 +- example/simple/stub/simple.json | 2 +- example/stream/stream.proto | 2 +- .../well_known_types/well_known_types.proto | 3 + protoc-gen-gripmock/generator.go | 1 - 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/example/simple/client/main.go b/example/simple/client/main.go index 2c6e8f96..990985d7 100644 --- a/example/simple/client/main.go +++ b/example/simple/client/main.go @@ -21,7 +21,7 @@ func main() { } defer conn.Close() - c := pb.NewSimpleClient(conn) + c := pb.NewGripmockClient(conn) // Contact the server and print out its response. name := "tokopedia" diff --git a/example/simple/simple.pb.go b/example/simple/simple.pb.go index e30768b9..ccb8fa77 100644 --- a/example/simple/simple.pb.go +++ b/example/simple/simple.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: simple.proto +// source: simple/simple.proto package simple @@ -35,7 +35,7 @@ func (m *Request) Reset() { *m = Request{} } func (m *Request) String() string { return proto.CompactTextString(m) } func (*Request) ProtoMessage() {} func (*Request) Descriptor() ([]byte, []int) { - return fileDescriptor_simple_7ef306436b49ce3d, []int{0} + return fileDescriptor_simple_e0ad890e6f6d32ea, []int{0} } func (m *Request) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Request.Unmarshal(m, b) @@ -74,7 +74,7 @@ func (m *Reply) Reset() { *m = Reply{} } func (m *Reply) String() string { return proto.CompactTextString(m) } func (*Reply) ProtoMessage() {} func (*Reply) Descriptor() ([]byte, []int) { - return fileDescriptor_simple_7ef306436b49ce3d, []int{1} + return fileDescriptor_simple_e0ad890e6f6d32ea, []int{1} } func (m *Reply) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_Reply.Unmarshal(m, b) @@ -114,83 +114,83 @@ var _ grpc.ClientConn // is compatible with the grpc package it is being compiled against. const _ = grpc.SupportPackageIsVersion4 -// SimpleClient is the client API for Simple service. +// GripmockClient is the client API for Gripmock service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type SimpleClient interface { +type GripmockClient interface { // simple unary method SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) } -type simpleClient struct { +type gripmockClient struct { cc *grpc.ClientConn } -func NewSimpleClient(cc *grpc.ClientConn) SimpleClient { - return &simpleClient{cc} +func NewGripmockClient(cc *grpc.ClientConn) GripmockClient { + return &gripmockClient{cc} } -func (c *simpleClient) SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) { +func (c *gripmockClient) SayHello(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Reply, error) { out := new(Reply) - err := c.cc.Invoke(ctx, "/simple.Simple/SayHello", in, out, opts...) + err := c.cc.Invoke(ctx, "/simple.Gripmock/SayHello", in, out, opts...) if err != nil { return nil, err } return out, nil } -// SimpleServer is the server API for Simple service. -type SimpleServer interface { +// GripmockServer is the server API for Gripmock service. +type GripmockServer interface { // simple unary method SayHello(context.Context, *Request) (*Reply, error) } -func RegisterSimpleServer(s *grpc.Server, srv SimpleServer) { - s.RegisterService(&_Simple_serviceDesc, srv) +func RegisterGripmockServer(s *grpc.Server, srv GripmockServer) { + s.RegisterService(&_Gripmock_serviceDesc, srv) } -func _Simple_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Gripmock_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(Request) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(SimpleServer).SayHello(ctx, in) + return srv.(GripmockServer).SayHello(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/simple.Simple/SayHello", + FullMethod: "/simple.Gripmock/SayHello", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(SimpleServer).SayHello(ctx, req.(*Request)) + return srv.(GripmockServer).SayHello(ctx, req.(*Request)) } return interceptor(ctx, in, info, handler) } -var _Simple_serviceDesc = grpc.ServiceDesc{ - ServiceName: "simple.Simple", - HandlerType: (*SimpleServer)(nil), +var _Gripmock_serviceDesc = grpc.ServiceDesc{ + ServiceName: "simple.Gripmock", + HandlerType: (*GripmockServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "SayHello", - Handler: _Simple_SayHello_Handler, + Handler: _Gripmock_SayHello_Handler, }, }, Streams: []grpc.StreamDesc{}, - Metadata: "simple.proto", -} - -func init() { proto.RegisterFile("simple.proto", fileDescriptor_simple_7ef306436b49ce3d) } - -var fileDescriptor_simple_7ef306436b49ce3d = []byte{ - // 131 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x29, 0xce, 0xcc, 0x2d, - 0xc8, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0x94, 0x64, 0xb9, 0xd8, - 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x84, 0xb8, 0x58, 0xf2, 0x12, 0x73, 0x53, 0x25, - 0x18, 0x15, 0x18, 0x35, 0x38, 0x83, 0xc0, 0x6c, 0x25, 0x45, 0x2e, 0xd6, 0xa0, 0xd4, 0x82, 0x9c, - 0x4a, 0x21, 0x09, 0x2e, 0xf6, 0xdc, 0xd4, 0xe2, 0xe2, 0xc4, 0x74, 0x98, 0x3c, 0x8c, 0x6b, 0x64, - 0xc2, 0xc5, 0x16, 0x0c, 0x36, 0x4b, 0x48, 0x8b, 0x8b, 0x23, 0x38, 0xb1, 0xd2, 0x23, 0x35, 0x27, - 0x27, 0x5f, 0x88, 0x5f, 0x0f, 0x6a, 0x1d, 0xd4, 0x74, 0x29, 0x5e, 0x84, 0x40, 0x41, 0x4e, 0x65, - 0x12, 0x1b, 0xd8, 0x19, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x19, 0x8a, 0x14, 0x59, 0x96, - 0x00, 0x00, 0x00, + Metadata: "simple/simple.proto", +} + +func init() { proto.RegisterFile("simple/simple.proto", fileDescriptor_simple_e0ad890e6f6d32ea) } + +var fileDescriptor_simple_e0ad890e6f6d32ea = []byte{ + // 138 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2e, 0xce, 0xcc, 0x2d, + 0xc8, 0x49, 0xd5, 0x87, 0x50, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x6c, 0x10, 0x9e, 0x92, + 0x2c, 0x17, 0x7b, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x71, 0x89, 0x90, 0x10, 0x17, 0x4b, 0x5e, 0x62, + 0x6e, 0xaa, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x98, 0xad, 0xa4, 0xc8, 0xc5, 0x1a, 0x94, + 0x5a, 0x90, 0x53, 0x29, 0x24, 0xc1, 0xc5, 0x9e, 0x9b, 0x5a, 0x5c, 0x9c, 0x98, 0x0e, 0x93, 0x87, + 0x71, 0x8d, 0xcc, 0xb8, 0x38, 0xdc, 0x8b, 0x32, 0x0b, 0x72, 0xf3, 0x93, 0xb3, 0x85, 0xb4, 0xb8, + 0x38, 0x82, 0x13, 0x2b, 0x3d, 0x52, 0x73, 0x72, 0xf2, 0x85, 0xf8, 0xf5, 0xa0, 0x16, 0x42, 0xcd, + 0x97, 0xe2, 0x45, 0x08, 0x14, 0xe4, 0x54, 0x26, 0xb1, 0x81, 0x1d, 0x62, 0x0c, 0x08, 0x00, 0x00, + 0xff, 0xff, 0x75, 0x88, 0x72, 0x2a, 0x9f, 0x00, 0x00, 0x00, } diff --git a/example/simple/simple.proto b/example/simple/simple.proto index 84c3a914..158f29e2 100644 --- a/example/simple/simple.proto +++ b/example/simple/simple.proto @@ -2,8 +2,8 @@ syntax = "proto3"; package simple; -// The greeting service definition. -service Simple { +// The Gripmock service definition. +service Gripmock { // simple unary method rpc SayHello (Request) returns (Reply); } diff --git a/example/simple/stub/simple.json b/example/simple/stub/simple.json index 61c12fda..866abb8e 100644 --- a/example/simple/stub/simple.json +++ b/example/simple/stub/simple.json @@ -1,5 +1,5 @@ { - "service":"Simple", + "service":"Gripmock", "method":"SayHello", "input":{ "equals":{ diff --git a/example/stream/stream.proto b/example/stream/stream.proto index de112f1b..502ab571 100644 --- a/example/stream/stream.proto +++ b/example/stream/stream.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package stream; -// The greeting service definition. +// The Gripmock service definition. service Gripmock { // server to client sreaming rpc serverStream (Request) returns (stream Reply); diff --git a/example/well_known_types/well_known_types.proto b/example/well_known_types/well_known_types.proto index 8668cb24..9c5ccce0 100644 --- a/example/well_known_types/well_known_types.proto +++ b/example/well_known_types/well_known_types.proto @@ -6,5 +6,8 @@ import "google/protobuf/empty.proto"; import "google/protobuf/api.proto"; service Gripmock { + // this shows us example on using WKT as dependency + // api.proto in particular has go_package alias with semicolon + // "google.golang.org/genproto/protobuf/api;api" rpc ApiInfo(google.protobuf.Empty) returns (google.protobuf.Api); } diff --git a/protoc-gen-gripmock/generator.go b/protoc-gen-gripmock/generator.go index 8e1a2cbf..0304886f 100644 --- a/protoc-gen-gripmock/generator.go +++ b/protoc-gen-gripmock/generator.go @@ -161,7 +161,6 @@ func resolveDependencies(protos []*descriptor.FileDescriptorProto) map[string]st aliasNum := 1 for _, dep := range depsFile { for _, proto := range protos { - pkg := proto.GetOptions().GetGoPackage() alias, pkg := getGoPackage(proto) // skip whether its not intended deps