From 9315ff979d7ac9e4fe54cea371cb4b3176183df7 Mon Sep 17 00:00:00 2001 From: Guillaume Delbergue Date: Mon, 3 Aug 2020 13:47:08 +0200 Subject: [PATCH] generator: fix extractServices slice index (#45) * generator: fix extractServices slice index Signed-off-by: Guillaume Delbergue * multifiles test Co-authored-by: Ahmad Muzakki --- .github/workflows/integration-test.yml | 4 + example/multi-files/client/main.go | 40 +++++ example/multi-files/entrypoint.sh | 7 + example/multi-files/file1.pb.go | 206 +++++++++++++++++++++++++ example/multi-files/file1.proto | 20 +++ example/multi-files/file2.pb.go | 206 +++++++++++++++++++++++++ example/multi-files/file2.proto | 19 +++ example/multi-files/stub/greet1.json | 15 ++ example/multi-files/stub/greet2.json | 15 ++ protoc-gen-gripmock/generator.go | 9 +- 10 files changed, 537 insertions(+), 4 deletions(-) create mode 100644 example/multi-files/client/main.go create mode 100755 example/multi-files/entrypoint.sh create mode 100644 example/multi-files/file1.pb.go create mode 100644 example/multi-files/file1.proto create mode 100644 example/multi-files/file2.pb.go create mode 100644 example/multi-files/file2.proto create mode 100644 example/multi-files/stub/greet1.json create mode 100644 example/multi-files/stub/greet2.json diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index af80b1c8..e4d4c8de 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -30,4 +30,8 @@ jobs: uses: ./ with: entrypoint: example/multi-package/entrypoint.sh + - name: Run Multi Files Example + uses: ./ + with: + entrypoint: example/multi-files/entrypoint.sh diff --git a/example/multi-files/client/main.go b/example/multi-files/client/main.go new file mode 100644 index 00000000..d6316e21 --- /dev/null +++ b/example/multi-files/client/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "context" + "log" + "time" + + pb "github.com/tokopedia/gripmock/example/multi-files" + "google.golang.org/grpc" +) + +func main() { + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) + defer cancel() + + // Set up a connection to the server. + conn, err := grpc.DialContext(ctx, "localhost:4770", grpc.WithInsecure(), grpc.WithBlock()) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + defer conn.Close() + + c := pb.NewGripmock1Client(conn) + + // Contact the server and print out its response. + r, err := c.SayHello(context.Background(), &pb.Request1{Name: "tokopedia"}) + if err != nil { + log.Fatalf("error from grpc: %v", err) + } + log.Printf("Greeting: %s", r.Message) + + c2 := pb.NewGripmock2Client(conn) + + // Contact the server and print out its response. + r2, err := c2.SayHello(context.Background(), &pb.Request2{Name: "tokopedia"}) + if err != nil { + log.Fatalf("error from grpc: %v", err) + } + log.Printf("Greeting: %s", r2.Message) +} diff --git a/example/multi-files/entrypoint.sh b/example/multi-files/entrypoint.sh new file mode 100755 index 00000000..2a0245f2 --- /dev/null +++ b/example/multi-files/entrypoint.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +# this file is used by .github/workflows/integration-test.yml + +gripmock --stub=example/multi-files/stub example/multi-files/file1.proto example/multi-files/file2.proto & + +go run example/multi-files/client/*.go \ No newline at end of file diff --git a/example/multi-files/file1.pb.go b/example/multi-files/file1.pb.go new file mode 100644 index 00000000..f52031de --- /dev/null +++ b/example/multi-files/file1.pb.go @@ -0,0 +1,206 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: file1.proto + +package multifiles + +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 +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +// The request message containing the user's name. +type Request1 struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request1) Reset() { *m = Request1{} } +func (m *Request1) String() string { return proto.CompactTextString(m) } +func (*Request1) ProtoMessage() {} +func (*Request1) Descriptor() ([]byte, []int) { + return fileDescriptor_file1_b87e0295d2d0c495, []int{0} +} +func (m *Request1) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request1.Unmarshal(m, b) +} +func (m *Request1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request1.Marshal(b, m, deterministic) +} +func (dst *Request1) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request1.Merge(dst, src) +} +func (m *Request1) XXX_Size() int { + return xxx_messageInfo_Request1.Size(m) +} +func (m *Request1) XXX_DiscardUnknown() { + xxx_messageInfo_Request1.DiscardUnknown(m) +} + +var xxx_messageInfo_Request1 proto.InternalMessageInfo + +func (m *Request1) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +// The response message containing the greetings +type Reply1 struct { + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + ReturnCode int32 `protobuf:"varint,2,opt,name=return_code,json=returnCode,proto3" json:"return_code,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Reply1) Reset() { *m = Reply1{} } +func (m *Reply1) String() string { return proto.CompactTextString(m) } +func (*Reply1) ProtoMessage() {} +func (*Reply1) Descriptor() ([]byte, []int) { + return fileDescriptor_file1_b87e0295d2d0c495, []int{1} +} +func (m *Reply1) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Reply1.Unmarshal(m, b) +} +func (m *Reply1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Reply1.Marshal(b, m, deterministic) +} +func (dst *Reply1) XXX_Merge(src proto.Message) { + xxx_messageInfo_Reply1.Merge(dst, src) +} +func (m *Reply1) XXX_Size() int { + return xxx_messageInfo_Reply1.Size(m) +} +func (m *Reply1) XXX_DiscardUnknown() { + xxx_messageInfo_Reply1.DiscardUnknown(m) +} + +var xxx_messageInfo_Reply1 proto.InternalMessageInfo + +func (m *Reply1) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + +func (m *Reply1) GetReturnCode() int32 { + if m != nil { + return m.ReturnCode + } + return 0 +} + +func init() { + proto.RegisterType((*Request1)(nil), "multifiles.Request1") + proto.RegisterType((*Reply1)(nil), "multifiles.Reply1") +} + +// 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 + +// Gripmock1Client is the client API for Gripmock1 service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type Gripmock1Client interface { + // simple unary method + SayHello(ctx context.Context, in *Request1, opts ...grpc.CallOption) (*Reply1, error) +} + +type gripmock1Client struct { + cc *grpc.ClientConn +} + +func NewGripmock1Client(cc *grpc.ClientConn) Gripmock1Client { + return &gripmock1Client{cc} +} + +func (c *gripmock1Client) SayHello(ctx context.Context, in *Request1, opts ...grpc.CallOption) (*Reply1, error) { + out := new(Reply1) + err := c.cc.Invoke(ctx, "/multifiles.Gripmock1/SayHello", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Gripmock1Server is the server API for Gripmock1 service. +type Gripmock1Server interface { + // simple unary method + SayHello(context.Context, *Request1) (*Reply1, error) +} + +func RegisterGripmock1Server(s *grpc.Server, srv Gripmock1Server) { + s.RegisterService(&_Gripmock1_serviceDesc, srv) +} + +func _Gripmock1_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request1) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(Gripmock1Server).SayHello(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/multifiles.Gripmock1/SayHello", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(Gripmock1Server).SayHello(ctx, req.(*Request1)) + } + return interceptor(ctx, in, info, handler) +} + +var _Gripmock1_serviceDesc = grpc.ServiceDesc{ + ServiceName: "multifiles.Gripmock1", + HandlerType: (*Gripmock1Server)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SayHello", + Handler: _Gripmock1_SayHello_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "file1.proto", +} + +func init() { proto.RegisterFile("file1.proto", fileDescriptor_file1_b87e0295d2d0c495) } + +var fileDescriptor_file1_b87e0295d2d0c495 = []byte{ + // 173 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4e, 0xcb, 0xcc, 0x49, + 0x35, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xca, 0x2d, 0xcd, 0x29, 0xc9, 0x04, 0x89, + 0x14, 0x2b, 0xc9, 0x71, 0x71, 0x04, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x18, 0x0a, 0x09, 0x71, + 0xb1, 0xe4, 0x25, 0xe6, 0xa6, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0xd9, 0x4a, 0xce, + 0x5c, 0x6c, 0x41, 0xa9, 0x05, 0x39, 0x95, 0x86, 0x42, 0x12, 0x5c, 0xec, 0xb9, 0xa9, 0xc5, 0xc5, + 0x89, 0xe9, 0x30, 0x05, 0x30, 0xae, 0x90, 0x3c, 0x17, 0x77, 0x51, 0x6a, 0x49, 0x69, 0x51, 0x5e, + 0x7c, 0x72, 0x7e, 0x4a, 0xaa, 0x04, 0x93, 0x02, 0xa3, 0x06, 0x6b, 0x10, 0x17, 0x44, 0xc8, 0x39, + 0x3f, 0x25, 0xd5, 0xc8, 0x91, 0x8b, 0xd3, 0xbd, 0x28, 0xb3, 0x20, 0x37, 0x3f, 0x39, 0xdb, 0x50, + 0xc8, 0x84, 0x8b, 0x23, 0x38, 0xb1, 0xd2, 0x23, 0x35, 0x27, 0x27, 0x5f, 0x48, 0x44, 0x0f, 0xe1, + 0x14, 0x3d, 0x98, 0x3b, 0xa4, 0x84, 0x50, 0x45, 0x41, 0xb6, 0x27, 0xb1, 0x81, 0x9d, 0x6e, 0x0c, + 0x08, 0x00, 0x00, 0xff, 0xff, 0xd7, 0xb7, 0x45, 0x56, 0xc9, 0x00, 0x00, 0x00, +} diff --git a/example/multi-files/file1.proto b/example/multi-files/file1.proto new file mode 100644 index 00000000..14c15042 --- /dev/null +++ b/example/multi-files/file1.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package multifiles; + +// The Gripmock service definition. +service Gripmock1 { + // simple unary method + rpc SayHello (Request1) returns (Reply1); +} + +// The request message containing the user's name. +message Request1 { + string name = 1; +} + +// The response message containing the greetings +message Reply1 { + string message = 1; + int32 return_code = 2; +} \ No newline at end of file diff --git a/example/multi-files/file2.pb.go b/example/multi-files/file2.pb.go new file mode 100644 index 00000000..fb0060ca --- /dev/null +++ b/example/multi-files/file2.pb.go @@ -0,0 +1,206 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: file2.proto + +package multifiles + +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 +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +// The request message containing the user's name. +type Request2 struct { + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Request2) Reset() { *m = Request2{} } +func (m *Request2) String() string { return proto.CompactTextString(m) } +func (*Request2) ProtoMessage() {} +func (*Request2) Descriptor() ([]byte, []int) { + return fileDescriptor_file2_6a46b4869ea0a05f, []int{0} +} +func (m *Request2) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Request2.Unmarshal(m, b) +} +func (m *Request2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Request2.Marshal(b, m, deterministic) +} +func (dst *Request2) XXX_Merge(src proto.Message) { + xxx_messageInfo_Request2.Merge(dst, src) +} +func (m *Request2) XXX_Size() int { + return xxx_messageInfo_Request2.Size(m) +} +func (m *Request2) XXX_DiscardUnknown() { + xxx_messageInfo_Request2.DiscardUnknown(m) +} + +var xxx_messageInfo_Request2 proto.InternalMessageInfo + +func (m *Request2) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +// The response message containing the greetings +type Reply2 struct { + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + ReturnCode int32 `protobuf:"varint,2,opt,name=return_code,json=returnCode,proto3" json:"return_code,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Reply2) Reset() { *m = Reply2{} } +func (m *Reply2) String() string { return proto.CompactTextString(m) } +func (*Reply2) ProtoMessage() {} +func (*Reply2) Descriptor() ([]byte, []int) { + return fileDescriptor_file2_6a46b4869ea0a05f, []int{1} +} +func (m *Reply2) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Reply2.Unmarshal(m, b) +} +func (m *Reply2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Reply2.Marshal(b, m, deterministic) +} +func (dst *Reply2) XXX_Merge(src proto.Message) { + xxx_messageInfo_Reply2.Merge(dst, src) +} +func (m *Reply2) XXX_Size() int { + return xxx_messageInfo_Reply2.Size(m) +} +func (m *Reply2) XXX_DiscardUnknown() { + xxx_messageInfo_Reply2.DiscardUnknown(m) +} + +var xxx_messageInfo_Reply2 proto.InternalMessageInfo + +func (m *Reply2) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + +func (m *Reply2) GetReturnCode() int32 { + if m != nil { + return m.ReturnCode + } + return 0 +} + +func init() { + proto.RegisterType((*Request2)(nil), "multifiles.Request2") + proto.RegisterType((*Reply2)(nil), "multifiles.Reply2") +} + +// 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 + +// Gripmock2Client is the client API for Gripmock2 service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type Gripmock2Client interface { + // simple unary method + SayHello(ctx context.Context, in *Request2, opts ...grpc.CallOption) (*Reply2, error) +} + +type gripmock2Client struct { + cc *grpc.ClientConn +} + +func NewGripmock2Client(cc *grpc.ClientConn) Gripmock2Client { + return &gripmock2Client{cc} +} + +func (c *gripmock2Client) SayHello(ctx context.Context, in *Request2, opts ...grpc.CallOption) (*Reply2, error) { + out := new(Reply2) + err := c.cc.Invoke(ctx, "/multifiles.Gripmock2/SayHello", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Gripmock2Server is the server API for Gripmock2 service. +type Gripmock2Server interface { + // simple unary method + SayHello(context.Context, *Request2) (*Reply2, error) +} + +func RegisterGripmock2Server(s *grpc.Server, srv Gripmock2Server) { + s.RegisterService(&_Gripmock2_serviceDesc, srv) +} + +func _Gripmock2_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Request2) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(Gripmock2Server).SayHello(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/multifiles.Gripmock2/SayHello", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(Gripmock2Server).SayHello(ctx, req.(*Request2)) + } + return interceptor(ctx, in, info, handler) +} + +var _Gripmock2_serviceDesc = grpc.ServiceDesc{ + ServiceName: "multifiles.Gripmock2", + HandlerType: (*Gripmock2Server)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "SayHello", + Handler: _Gripmock2_SayHello_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "file2.proto", +} + +func init() { proto.RegisterFile("file2.proto", fileDescriptor_file2_6a46b4869ea0a05f) } + +var fileDescriptor_file2_6a46b4869ea0a05f = []byte{ + // 173 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x8e, 0xb1, 0x0e, 0x82, 0x40, + 0x10, 0x44, 0x83, 0x51, 0x84, 0xa5, 0xdb, 0x58, 0x10, 0x0b, 0x25, 0x54, 0x54, 0x14, 0xa7, 0x3f, + 0x60, 0x28, 0xb4, 0x3e, 0x3f, 0xc0, 0x20, 0xac, 0x86, 0x78, 0xc7, 0xe2, 0xdd, 0x51, 0xf0, 0xf7, + 0x06, 0x0c, 0x31, 0x76, 0x33, 0x2f, 0x93, 0xcc, 0x83, 0xe8, 0xd1, 0x28, 0x12, 0x79, 0x67, 0xd8, + 0x31, 0x82, 0xee, 0x95, 0x6b, 0x46, 0x62, 0xd3, 0x1d, 0x04, 0x92, 0xde, 0x3d, 0x59, 0x27, 0x10, + 0x61, 0xd9, 0x96, 0x9a, 0x62, 0x2f, 0xf1, 0xb2, 0x50, 0x4e, 0x39, 0x2d, 0xc0, 0x97, 0xd4, 0xa9, + 0x41, 0x60, 0x0c, 0x6b, 0x4d, 0xd6, 0x96, 0xcf, 0x79, 0x30, 0x57, 0xdc, 0x43, 0x64, 0xc8, 0xf5, + 0xa6, 0xbd, 0x55, 0x5c, 0x53, 0xbc, 0x48, 0xbc, 0x6c, 0x25, 0xe1, 0x8b, 0x0a, 0xae, 0x49, 0x9c, + 0x20, 0x3c, 0x9b, 0xa6, 0xd3, 0x5c, 0xbd, 0x04, 0x1e, 0x21, 0xb8, 0x96, 0xc3, 0x85, 0x94, 0x62, + 0xdc, 0xe4, 0x3f, 0x95, 0x7c, 0xf6, 0xd8, 0xe2, 0x3f, 0x1d, 0xdf, 0xef, 0xfe, 0xa4, 0x7e, 0xf8, + 0x04, 0x00, 0x00, 0xff, 0xff, 0x58, 0xdc, 0x5d, 0xb0, 0xc9, 0x00, 0x00, 0x00, +} diff --git a/example/multi-files/file2.proto b/example/multi-files/file2.proto new file mode 100644 index 00000000..9139cdc9 --- /dev/null +++ b/example/multi-files/file2.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package multifiles; + +service Gripmock2 { + // simple unary method + rpc SayHello (Request2) returns (Reply2); +} + +// The request message containing the user's name. +message Request2 { + string name = 1; +} + +// The response message containing the greetings +message Reply2 { + string message = 1; + int32 return_code = 2; +} \ No newline at end of file diff --git a/example/multi-files/stub/greet1.json b/example/multi-files/stub/greet1.json new file mode 100644 index 00000000..1d220379 --- /dev/null +++ b/example/multi-files/stub/greet1.json @@ -0,0 +1,15 @@ +{ + "service": "Gripmock1", + "method": "SayHello", + "input": { + "equals": { + "name": "tokopedia" + } + }, + "output": { + "data": { + "message": "Hello Tokopedia 1", + "return_code": 1 + } + } +} diff --git a/example/multi-files/stub/greet2.json b/example/multi-files/stub/greet2.json new file mode 100644 index 00000000..e902237a --- /dev/null +++ b/example/multi-files/stub/greet2.json @@ -0,0 +1,15 @@ +{ + "service": "Gripmock2", + "method": "SayHello", + "input": { + "equals": { + "name": "tokopedia" + } + }, + "output": { + "data": { + "message": "Hello Tokopedia 2", + "return_code": 1 + } + } +} diff --git a/protoc-gen-gripmock/generator.go b/protoc-gen-gripmock/generator.go index 4622b980..eb9cf7c9 100644 --- a/protoc-gen-gripmock/generator.go +++ b/protoc-gen-gripmock/generator.go @@ -206,9 +206,9 @@ func getGoPackage(proto *descriptor.FileDescriptorProto) (alias string, goPackag func extractServices(protos []*descriptor.FileDescriptorProto) []Service { svcTmp := []Service{} for _, proto := range protos { - for i, svc := range proto.GetService() { - svcTmp = append(svcTmp, Service{}) - svcTmp[i].Name = svc.GetName() + for _, svc := range proto.GetService() { + var s Service + s.Name = svc.GetName() methods := make([]methodTemplate, len(svc.Method)) for j, method := range svc.Method { tipe := methodTypeStandard @@ -228,7 +228,8 @@ func extractServices(protos []*descriptor.FileDescriptorProto) []Service { MethodType: tipe, } } - svcTmp[i].Methods = methods + s.Methods = methods + svcTmp = append(svcTmp, s) } } return svcTmp