diff --git a/.gitignore b/.gitignore index 53b035e4..6f74a698 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ gin-bin # Output of the go coverage tool, specifically when used with LiteIDE *.out + +# IDE settings +.idea \ No newline at end of file diff --git a/examples/dummy/output/export.json b/examples/dummy/output/export.json index e3735f81..7d9b5d66 100644 --- a/examples/dummy/output/export.json +++ b/examples/dummy/output/export.json @@ -1,10 +1,10 @@ { - "build-date": "2017-05-19T20:09:45.954357761+02:00", - "build-hostname": "manfred-spacegray.aircard", + "build-date": "2021-04-12T10:42:31.388860713Z", + "build-hostname": "fwrz", "build-user": "moul", - "pwd": "/Users/moul/Git/moul/protoc-gen-gotemplate/examples/dummy", + "pwd": "/home/moul/go/src/moul.io/protoc-gen-gotemplate/examples/dummy", "debug": false, - "destination-dir": ".", + "destination-dir": "", "file": { "name": "dummy.proto", "package": "dummy", @@ -118,8 +118,8 @@ ], "span": [ 2, - 8, - 13 + 0, + 14 ] }, { @@ -159,21 +159,6 @@ 16 ] }, - { - "path": [ - 4, - 0, - 2, - 0, - 4 - ], - "span": [ - 5, - 2, - 4, - 16 - ] - }, { "path": [ 4, @@ -229,21 +214,6 @@ 17 ] }, - { - "path": [ - 4, - 0, - 2, - 1, - 4 - ], - "span": [ - 6, - 2, - 5, - 16 - ] - }, { "path": [ 4, @@ -299,21 +269,6 @@ 16 ] }, - { - "path": [ - 4, - 0, - 2, - 2, - 4 - ], - "span": [ - 7, - 2, - 6, - 17 - ] - }, { "path": [ 4, @@ -369,21 +324,6 @@ 16 ] }, - { - "path": [ - 4, - 0, - 2, - 3, - 4 - ], - "span": [ - 8, - 2, - 7, - 16 - ] - }, { "path": [ 4, @@ -532,21 +472,6 @@ 16 ] }, - { - "path": [ - 4, - 1, - 2, - 0, - 4 - ], - "span": [ - 13, - 2, - 12, - 16 - ] - }, { "path": [ 4, @@ -602,21 +527,6 @@ 17 ] }, - { - "path": [ - 4, - 1, - 2, - 1, - 4 - ], - "span": [ - 14, - 2, - 13, - 16 - ] - }, { "path": [ 4, diff --git a/examples/flow/output/test/test_grpc_js.js b/examples/flow/output/test/test_grpc_js.js index 9410b6ef..70e91ba7 100644 --- a/examples/flow/output/test/test_grpc_js.js +++ b/examples/flow/output/test/test_grpc_js.js @@ -261,7 +261,7 @@ export default { TestService: { - testNoStream: { + testnostream: { path: '/test.TestService/TestNoStream', requestStream: false, responseStream: false, @@ -272,7 +272,7 @@ export default { responseSerialize: serialize_test_TestNoStreamReply, responseDeserialize: deserialize_test_TestNoStreamReply, }, - testStreamRequest: { + teststreamrequest: { path: '/test.TestService/TestStreamRequest', requestStream: true, responseStream: false, @@ -283,7 +283,7 @@ export default { responseSerialize: serialize_test_TestStreamRequestReply, responseDeserialize: deserialize_test_TestStreamRequestReply, }, - testStreamReply: { + teststreamreply: { path: '/test.TestService/TestStreamReply', requestStream: false, responseStream: true, @@ -294,7 +294,7 @@ export default { responseSerialize: serialize_test_TestStreamReplyReply, responseDeserialize: deserialize_test_TestStreamReplyReply, }, - testStreamBoth: { + teststreamboth: { path: '/test.TestService/TestStreamBoth', requestStream: true, responseStream: true, diff --git a/examples/go-generate/example.go b/examples/go-generate/example.go index f1dfe3c5..83805324 100644 --- a/examples/go-generate/example.go +++ b/examples/go-generate/example.go @@ -1,4 +1,4 @@ package example //go:generate protoc --go_out=./gen/ example.proto -//go:generate protoc --gotemplate_out=./gen/ example.proto +//go:generate protoc --gotemplate_out=template_dir=templates:./gen/ example.proto diff --git a/examples/go-generate/example.proto b/examples/go-generate/example.proto index 42f70fd7..2029964c 100644 --- a/examples/go-generate/example.proto +++ b/examples/go-generate/example.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package example; +option go_package = "./"; + service Sum { rpc Sum(SumRequest) returns (SumReply) {}; } diff --git a/examples/go-generate/gen/example.pb.go b/examples/go-generate/gen/example.pb.go index 800386a4..5f20c1be 100644 --- a/examples/go-generate/gen/example.pb.go +++ b/examples/go-generate/gen/example.pb.go @@ -1,89 +1,217 @@ -// Code generated by protoc-gen-go. +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.15.5 // source: example.proto -// DO NOT EDIT! -/* -Package example is a generated protocol buffer package. +package __ -It is generated from these files: - example.proto +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) -It has these top-level messages: - SumRequest - SumReply -*/ -package example +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +type SumRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf + A int32 `protobuf:"varint,1,opt,name=a,proto3" json:"a,omitempty"` + B int32 `protobuf:"varint,2,opt,name=b,proto3" json:"b,omitempty"` +} -// 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 +func (x *SumRequest) Reset() { + *x = SumRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_example_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} -type SumRequest struct { - A int32 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"` - B int32 `protobuf:"varint,2,opt,name=b" json:"b,omitempty"` +func (x *SumRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SumRequest) ProtoMessage() {} + +func (x *SumRequest) ProtoReflect() protoreflect.Message { + mi := &file_example_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *SumRequest) Reset() { *m = SumRequest{} } -func (m *SumRequest) String() string { return proto.CompactTextString(m) } -func (*SumRequest) ProtoMessage() {} -func (*SumRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } +// Deprecated: Use SumRequest.ProtoReflect.Descriptor instead. +func (*SumRequest) Descriptor() ([]byte, []int) { + return file_example_proto_rawDescGZIP(), []int{0} +} -func (m *SumRequest) GetA() int32 { - if m != nil { - return m.A +func (x *SumRequest) GetA() int32 { + if x != nil { + return x.A } return 0 } -func (m *SumRequest) GetB() int32 { - if m != nil { - return m.B +func (x *SumRequest) GetB() int32 { + if x != nil { + return x.B } return 0 } type SumReply struct { - C int32 `protobuf:"varint,1,opt,name=c" json:"c,omitempty"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + C int32 `protobuf:"varint,1,opt,name=c,proto3" json:"c,omitempty"` +} + +func (x *SumReply) Reset() { + *x = SumReply{} + if protoimpl.UnsafeEnabled { + mi := &file_example_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -func (m *SumReply) Reset() { *m = SumReply{} } -func (m *SumReply) String() string { return proto.CompactTextString(m) } -func (*SumReply) ProtoMessage() {} -func (*SumReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } +func (x *SumReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SumReply) ProtoMessage() {} + +func (x *SumReply) ProtoReflect() protoreflect.Message { + mi := &file_example_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SumReply.ProtoReflect.Descriptor instead. +func (*SumReply) Descriptor() ([]byte, []int) { + return file_example_proto_rawDescGZIP(), []int{1} +} -func (m *SumReply) GetC() int32 { - if m != nil { - return m.C +func (x *SumReply) GetC() int32 { + if x != nil { + return x.C } return 0 } -func init() { - proto.RegisterType((*SumRequest)(nil), "example.SumRequest") - proto.RegisterType((*SumReply)(nil), "example.SumReply") +var File_example_proto protoreflect.FileDescriptor + +var file_example_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x07, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x22, 0x28, 0x0a, 0x0a, 0x53, 0x75, 0x6d, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0c, 0x0a, 0x01, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x01, 0x61, 0x12, 0x0c, 0x0a, 0x01, 0x62, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x01, 0x62, 0x22, 0x18, 0x0a, 0x08, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x0c, + 0x0a, 0x01, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x63, 0x32, 0x36, 0x0a, 0x03, + 0x53, 0x75, 0x6d, 0x12, 0x2f, 0x0a, 0x03, 0x53, 0x75, 0x6d, 0x12, 0x13, 0x2e, 0x65, 0x78, 0x61, + 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x11, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x70, + 0x6c, 0x79, 0x22, 0x00, 0x42, 0x04, 0x5a, 0x02, 0x2e, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } -func init() { proto.RegisterFile("example.proto", fileDescriptor0) } +var ( + file_example_proto_rawDescOnce sync.Once + file_example_proto_rawDescData = file_example_proto_rawDesc +) -var fileDescriptor0 = []byte{ - // 124 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4d, 0xad, 0x48, 0xcc, - 0x2d, 0xc8, 0x49, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x87, 0x72, 0x95, 0x34, 0xb8, - 0xb8, 0x82, 0x4b, 0x73, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0x78, 0xb8, 0x18, 0x13, - 0x25, 0x18, 0x15, 0x18, 0x35, 0x58, 0x83, 0x18, 0x13, 0x41, 0xbc, 0x24, 0x09, 0x26, 0x08, 0x2f, - 0x49, 0x49, 0x82, 0x8b, 0x03, 0xac, 0xb2, 0x20, 0xa7, 0x12, 0x24, 0x93, 0x0c, 0x53, 0x97, 0x6c, - 0x64, 0xc6, 0xc5, 0x1c, 0x5c, 0x9a, 0x2b, 0xa4, 0x0f, 0xa1, 0x84, 0xf5, 0x60, 0x56, 0x21, 0x0c, - 0x96, 0x12, 0x44, 0x15, 0x2c, 0xc8, 0xa9, 0x54, 0x62, 0x48, 0x62, 0x03, 0xbb, 0xc5, 0x18, 0x10, - 0x00, 0x00, 0xff, 0xff, 0x2b, 0xf1, 0xe9, 0x56, 0x9c, 0x00, 0x00, 0x00, +func file_example_proto_rawDescGZIP() []byte { + file_example_proto_rawDescOnce.Do(func() { + file_example_proto_rawDescData = protoimpl.X.CompressGZIP(file_example_proto_rawDescData) + }) + return file_example_proto_rawDescData +} + +var file_example_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_example_proto_goTypes = []interface{}{ + (*SumRequest)(nil), // 0: example.SumRequest + (*SumReply)(nil), // 1: example.SumReply +} +var file_example_proto_depIdxs = []int32{ + 0, // 0: example.Sum.Sum:input_type -> example.SumRequest + 1, // 1: example.Sum.Sum:output_type -> example.SumReply + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_example_proto_init() } +func file_example_proto_init() { + if File_example_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_example_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SumRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_example_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SumReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_example_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_example_proto_goTypes, + DependencyIndexes: file_example_proto_depIdxs, + MessageInfos: file_example_proto_msgTypes, + }.Build() + File_example_proto = out.File + file_example_proto_rawDesc = nil + file_example_proto_goTypes = nil + file_example_proto_depIdxs = nil } diff --git a/examples/go.mod b/examples/go.mod index e69de29b..ed8bb6e7 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -0,0 +1 @@ +module moul.io/protoc-gen-gotemplates/example \ No newline at end of file diff --git a/examples/helpers/example.txt b/examples/helpers/example.txt index 0224f48f..554ea20b 100644 --- a/examples/helpers/example.txt +++ b/examples/helpers/example.txt @@ -25,7 +25,7 @@ {{abbrev 5 "hello world"}}: he... {{abbrevboth 5 10 "1234 5678 9123"}}: ...5678... {{initials "First Try"}}: FT -{{randNumeric 3}}: 528 +{{randNumeric 3}}: 616 {{- /*{{wrap 80 $someText}}*/}}: {{wrapWith 5 "\t" "Hello World"}}: Hello World {{contains "cat" "catch"}}: true diff --git a/examples/import/Makefile b/examples/import/Makefile index 9cf5779e..6335b2e9 100644 --- a/examples/import/Makefile +++ b/examples/import/Makefile @@ -4,7 +4,7 @@ build: # generate pb.go inluding imported proto protoc --go_out=Mproto/common.proto=moul.io/protoc-gen-gotemplate/examples/import/output/models/common:./output proto/article.proto - protoc --go_out=,plugins=grpc:./output proto/common.proto + protoc --go_out=:./output proto/common.proto # build our go file based on our template protoc -I. --gotemplate_out=template_dir=templates,debug=true:output proto/article.proto diff --git a/examples/import/output/models/article/article.pb.go b/examples/import/output/models/article/article.pb.go index 16b26513..90f19043 100644 --- a/examples/import/output/models/article/article.pb.go +++ b/examples/import/output/models/article/article.pb.go @@ -1,141 +1,369 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.15.5 // source: proto/article.proto -/* -Package article is a generated protocol buffer package. +package article -It is generated from these files: - proto/article.proto +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + common "moul.io/protoc-gen-gotemplate/examples/import/output/models/common" + reflect "reflect" + sync "sync" +) -It has these top-level messages: - GetArticleRequest - GetArticleResponse - Article -*/ -package article +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import common "moul.io/protoc-gen-gotemplate/examples/import/output/models/common" +type GetArticleRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf + Getarticle *common.GetArticle `protobuf:"bytes,1,opt,name=getarticle,proto3" json:"getarticle,omitempty"` +} -// 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 +func (x *GetArticleRequest) Reset() { + *x = GetArticleRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_article_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} -type GetArticleRequest struct { - Getarticle *common.GetArticle `protobuf:"bytes,1,opt,name=getarticle" json:"getarticle,omitempty"` +func (x *GetArticleRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetArticleRequest) ProtoMessage() {} + +func (x *GetArticleRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_article_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *GetArticleRequest) Reset() { *m = GetArticleRequest{} } -func (m *GetArticleRequest) String() string { return proto.CompactTextString(m) } -func (*GetArticleRequest) ProtoMessage() {} -func (*GetArticleRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } +// Deprecated: Use GetArticleRequest.ProtoReflect.Descriptor instead. +func (*GetArticleRequest) Descriptor() ([]byte, []int) { + return file_proto_article_proto_rawDescGZIP(), []int{0} +} -func (m *GetArticleRequest) GetGetarticle() *common.GetArticle { - if m != nil { - return m.Getarticle +func (x *GetArticleRequest) GetGetarticle() *common.GetArticle { + if x != nil { + return x.Getarticle } return nil } type GetArticleResponse struct { - Article *Article `protobuf:"bytes,1,opt,name=article" json:"article,omitempty"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Article *Article `protobuf:"bytes,1,opt,name=article,proto3" json:"article,omitempty"` // The generated output should write []*GetArticleResponse_Storage.Storage for this field. - Storages []*GetArticleResponse_Storage `protobuf:"bytes,2,rep,name=storages" json:"storages,omitempty"` + Storages []*GetArticleResponse_Storage `protobuf:"bytes,2,rep,name=storages,proto3" json:"storages,omitempty"` } -func (m *GetArticleResponse) Reset() { *m = GetArticleResponse{} } -func (m *GetArticleResponse) String() string { return proto.CompactTextString(m) } -func (*GetArticleResponse) ProtoMessage() {} -func (*GetArticleResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } +func (x *GetArticleResponse) Reset() { + *x = GetArticleResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_article_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} -func (m *GetArticleResponse) GetArticle() *Article { - if m != nil { - return m.Article +func (x *GetArticleResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetArticleResponse) ProtoMessage() {} + +func (x *GetArticleResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_article_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetArticleResponse.ProtoReflect.Descriptor instead. +func (*GetArticleResponse) Descriptor() ([]byte, []int) { + return file_proto_article_proto_rawDescGZIP(), []int{1} +} + +func (x *GetArticleResponse) GetArticle() *Article { + if x != nil { + return x.Article } return nil } -func (m *GetArticleResponse) GetStorages() []*GetArticleResponse_Storage { - if m != nil { - return m.Storages +func (x *GetArticleResponse) GetStorages() []*GetArticleResponse_Storage { + if x != nil { + return x.Storages } return nil } -type GetArticleResponse_Storage struct { - Code string `protobuf:"bytes,1,opt,name=code" json:"code,omitempty"` +type Article struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *Article) Reset() { + *x = Article{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_article_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Article) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *GetArticleResponse_Storage) Reset() { *m = GetArticleResponse_Storage{} } -func (m *GetArticleResponse_Storage) String() string { return proto.CompactTextString(m) } -func (*GetArticleResponse_Storage) ProtoMessage() {} -func (*GetArticleResponse_Storage) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1, 0} } +func (*Article) ProtoMessage() {} -func (m *GetArticleResponse_Storage) GetCode() string { - if m != nil { - return m.Code +func (x *Article) ProtoReflect() protoreflect.Message { + mi := &file_proto_article_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms } - return "" + return mi.MessageOf(x) } -type Article struct { - Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"` +// Deprecated: Use Article.ProtoReflect.Descriptor instead. +func (*Article) Descriptor() ([]byte, []int) { + return file_proto_article_proto_rawDescGZIP(), []int{2} } -func (m *Article) Reset() { *m = Article{} } -func (m *Article) String() string { return proto.CompactTextString(m) } -func (*Article) ProtoMessage() {} -func (*Article) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } +func (x *Article) GetId() string { + if x != nil { + return x.Id + } + return "" +} -func (m *Article) GetId() string { - if m != nil { - return m.Id +func (x *Article) GetName() string { + if x != nil { + return x.Name } return "" } -func (m *Article) GetName() string { - if m != nil { - return m.Name +type GetArticleResponse_Storage struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Code string `protobuf:"bytes,1,opt,name=code,proto3" json:"code,omitempty"` +} + +func (x *GetArticleResponse_Storage) Reset() { + *x = GetArticleResponse_Storage{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_article_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetArticleResponse_Storage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetArticleResponse_Storage) ProtoMessage() {} + +func (x *GetArticleResponse_Storage) ProtoReflect() protoreflect.Message { + mi := &file_proto_article_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetArticleResponse_Storage.ProtoReflect.Descriptor instead. +func (*GetArticleResponse_Storage) Descriptor() ([]byte, []int) { + return file_proto_article_proto_rawDescGZIP(), []int{1, 0} +} + +func (x *GetArticleResponse_Storage) GetCode() string { + if x != nil { + return x.Code } return "" } -func init() { - proto.RegisterType((*GetArticleRequest)(nil), "company.GetArticleRequest") - proto.RegisterType((*GetArticleResponse)(nil), "company.GetArticleResponse") - proto.RegisterType((*GetArticleResponse_Storage)(nil), "company.GetArticleResponse.Storage") - proto.RegisterType((*Article)(nil), "company.Article") -} - -func init() { proto.RegisterFile("proto/article.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 256 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0x41, 0x4b, 0xc4, 0x30, - 0x10, 0x85, 0x6d, 0x15, 0xab, 0xb3, 0x20, 0x3a, 0x82, 0x94, 0x8a, 0xb0, 0xd4, 0xcb, 0x22, 0x18, - 0xa1, 0x1e, 0x3d, 0x88, 0x5e, 0x7a, 0xaf, 0x78, 0xf1, 0x56, 0xd3, 0x61, 0x29, 0x6c, 0x3a, 0xb5, - 0x89, 0x82, 0xff, 0xc6, 0x9f, 0x2a, 0x9b, 0x4c, 0xd7, 0x8a, 0xb2, 0xa7, 0x4e, 0xf3, 0xbe, 0xf7, - 0xf2, 0xc8, 0xc0, 0x69, 0x3f, 0xb0, 0xe3, 0x9b, 0x7a, 0x70, 0xad, 0x5e, 0x91, 0xf2, 0x7f, 0x98, - 0x68, 0x36, 0x7d, 0xdd, 0x7d, 0x66, 0x18, 0x54, 0xcd, 0xc6, 0x70, 0x17, 0xc4, 0xbc, 0x84, 0x93, - 0x92, 0xdc, 0x43, 0x30, 0x54, 0xf4, 0xf6, 0x4e, 0xd6, 0x61, 0x01, 0xb0, 0x24, 0x27, 0x29, 0x69, - 0x34, 0x8f, 0x16, 0xb3, 0x02, 0x95, 0xf8, 0x26, 0xf8, 0x84, 0xca, 0xbf, 0x22, 0xc0, 0x69, 0x92, - 0xed, 0xb9, 0xb3, 0x84, 0x57, 0x90, 0xfc, 0xce, 0x39, 0x56, 0x52, 0x47, 0x8d, 0xe8, 0x08, 0xe0, - 0x3d, 0x1c, 0x58, 0xc7, 0x43, 0xbd, 0x24, 0x9b, 0xc6, 0xf3, 0xdd, 0xc5, 0xac, 0xb8, 0xdc, 0xc0, - 0x7f, 0xa3, 0xd5, 0x53, 0x60, 0xab, 0x8d, 0x29, 0xbb, 0x80, 0x44, 0x0e, 0x11, 0x61, 0x4f, 0x73, - 0x13, 0x2e, 0x3d, 0xac, 0xfc, 0x9c, 0x5f, 0x43, 0x22, 0x19, 0x78, 0x04, 0x71, 0xdb, 0x88, 0x18, - 0xb7, 0xcd, 0x1a, 0xef, 0x6a, 0x43, 0x69, 0x1c, 0xf0, 0xf5, 0x5c, 0x3c, 0x03, 0x48, 0x33, 0xfb, - 0xa1, 0xb1, 0x04, 0xf8, 0xe9, 0x80, 0xd9, 0xbf, 0xc5, 0xfc, 0xeb, 0x65, 0xe7, 0x5b, 0x4a, 0xe7, - 0x3b, 0x8f, 0xe9, 0xcb, 0x99, 0xe1, 0x86, 0x56, 0x76, 0x5c, 0xd3, 0x9d, 0x7c, 0x5f, 0xf7, 0xfd, - 0x4a, 0x6e, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x93, 0xb5, 0x4a, 0x95, 0xc6, 0x01, 0x00, 0x00, +var File_proto_article_proto protoreflect.FileDescriptor + +var file_proto_article_proto_rawDesc = []byte{ + 0x0a, 0x13, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x1a, 0x12, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x47, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x32, 0x0a, 0x0a, 0x67, 0x65, 0x74, 0x61, 0x72, + 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x63, 0x6f, + 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, + 0x0a, 0x67, 0x65, 0x74, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x22, 0xa0, 0x01, 0x0a, 0x12, + 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x2a, 0x0a, 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x2e, 0x41, 0x72, + 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x07, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x3f, + 0x0a, 0x08, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x23, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x72, + 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x53, 0x74, + 0x6f, 0x72, 0x61, 0x67, 0x65, 0x52, 0x08, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x73, 0x1a, + 0x1d, 0x0a, 0x07, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x2d, + 0x0a, 0x07, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x32, 0x55, 0x0a, + 0x0a, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x73, 0x76, 0x63, 0x12, 0x47, 0x0a, 0x0a, 0x47, + 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x1a, 0x2e, 0x63, 0x6f, 0x6d, 0x70, + 0x61, 0x6e, 0x79, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x6e, 0x79, 0x2e, + 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x18, 0x5a, 0x16, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2f, 0x61, + 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x3b, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_article_proto_rawDescOnce sync.Once + file_proto_article_proto_rawDescData = file_proto_article_proto_rawDesc +) + +func file_proto_article_proto_rawDescGZIP() []byte { + file_proto_article_proto_rawDescOnce.Do(func() { + file_proto_article_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_article_proto_rawDescData) + }) + return file_proto_article_proto_rawDescData +} + +var file_proto_article_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_proto_article_proto_goTypes = []interface{}{ + (*GetArticleRequest)(nil), // 0: company.GetArticleRequest + (*GetArticleResponse)(nil), // 1: company.GetArticleResponse + (*Article)(nil), // 2: company.Article + (*GetArticleResponse_Storage)(nil), // 3: company.GetArticleResponse.Storage + (*common.GetArticle)(nil), // 4: common.GetArticle +} +var file_proto_article_proto_depIdxs = []int32{ + 4, // 0: company.GetArticleRequest.getarticle:type_name -> common.GetArticle + 2, // 1: company.GetArticleResponse.article:type_name -> company.Article + 3, // 2: company.GetArticleResponse.storages:type_name -> company.GetArticleResponse.Storage + 0, // 3: company.articlesvc.GetArticle:input_type -> company.GetArticleRequest + 1, // 4: company.articlesvc.GetArticle:output_type -> company.GetArticleResponse + 4, // [4:5] is the sub-list for method output_type + 3, // [3:4] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_proto_article_proto_init() } +func file_proto_article_proto_init() { + if File_proto_article_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_article_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetArticleRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_article_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetArticleResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_article_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Article); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_article_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetArticleResponse_Storage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_article_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_article_proto_goTypes, + DependencyIndexes: file_proto_article_proto_depIdxs, + MessageInfos: file_proto_article_proto_msgTypes, + }.Build() + File_proto_article_proto = out.File + file_proto_article_proto_rawDesc = nil + file_proto_article_proto_goTypes = nil + file_proto_article_proto_depIdxs = nil } diff --git a/examples/import/output/models/common/common.pb.go b/examples/import/output/models/common/common.pb.go index 6cfb9baa..8a320c8e 100644 --- a/examples/import/output/models/common/common.pb.go +++ b/examples/import/output/models/common/common.pb.go @@ -1,69 +1,152 @@ // Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.15.5 // source: proto/common.proto -/* -Package common is a generated protocol buffer package. +package common -It is generated from these files: - proto/common.proto +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) -It has these top-level messages: - GetArticle -*/ -package common +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +type GetArticle struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Tenant string `protobuf:"bytes,2,opt,name=tenant,proto3" json:"tenant,omitempty"` +} -// 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 +func (x *GetArticle) Reset() { + *x = GetArticle{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_common_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} -type GetArticle struct { - Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"` - Tenant string `protobuf:"bytes,2,opt,name=tenant" json:"tenant,omitempty"` +func (x *GetArticle) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *GetArticle) Reset() { *m = GetArticle{} } -func (m *GetArticle) String() string { return proto.CompactTextString(m) } -func (*GetArticle) ProtoMessage() {} -func (*GetArticle) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } +func (*GetArticle) ProtoMessage() {} -func (m *GetArticle) GetId() string { - if m != nil { - return m.Id +func (x *GetArticle) ProtoReflect() protoreflect.Message { + mi := &file_proto_common_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetArticle.ProtoReflect.Descriptor instead. +func (*GetArticle) Descriptor() ([]byte, []int) { + return file_proto_common_proto_rawDescGZIP(), []int{0} +} + +func (x *GetArticle) GetId() string { + if x != nil { + return x.Id } return "" } -func (m *GetArticle) GetTenant() string { - if m != nil { - return m.Tenant +func (x *GetArticle) GetTenant() string { + if x != nil { + return x.Tenant } return "" } -func init() { - proto.RegisterType((*GetArticle)(nil), "common.GetArticle") +var File_proto_common_proto protoreflect.FileDescriptor + +var file_proto_common_proto_rawDesc = []byte{ + 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x22, 0x34, 0x0a, 0x0a, + 0x47, 0x65, 0x74, 0x41, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x65, + 0x6e, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x74, 0x65, 0x6e, 0x61, + 0x6e, 0x74, 0x42, 0x16, 0x5a, 0x14, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2f, 0x63, 0x6f, 0x6d, + 0x6d, 0x6f, 0x6e, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +} + +var ( + file_proto_common_proto_rawDescOnce sync.Once + file_proto_common_proto_rawDescData = file_proto_common_proto_rawDesc +) + +func file_proto_common_proto_rawDescGZIP() []byte { + file_proto_common_proto_rawDescOnce.Do(func() { + file_proto_common_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_common_proto_rawDescData) + }) + return file_proto_common_proto_rawDescData +} + +var file_proto_common_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_proto_common_proto_goTypes = []interface{}{ + (*GetArticle)(nil), // 0: common.GetArticle +} +var file_proto_common_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } -func init() { proto.RegisterFile("proto/common.proto", fileDescriptor0) } - -var fileDescriptor0 = []byte{ - // 110 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x28, 0xca, 0x2f, - 0xc9, 0xd7, 0x4f, 0xce, 0xcf, 0xcd, 0xcd, 0xcf, 0xd3, 0x03, 0x73, 0x84, 0xd8, 0x20, 0x3c, 0x25, - 0x13, 0x2e, 0x2e, 0xf7, 0xd4, 0x12, 0xc7, 0xa2, 0x92, 0xcc, 0xe4, 0x9c, 0x54, 0x21, 0x3e, 0x2e, - 0xa6, 0xcc, 0x14, 0x09, 0x46, 0x05, 0x46, 0x0d, 0xce, 0x20, 0xa6, 0xcc, 0x14, 0x21, 0x31, 0x2e, - 0xb6, 0x92, 0xd4, 0xbc, 0xc4, 0xbc, 0x12, 0x09, 0x26, 0xb0, 0x18, 0x94, 0xe7, 0x24, 0x16, 0x25, - 0x92, 0x9b, 0x9f, 0x92, 0x9a, 0x53, 0x0c, 0x35, 0xd4, 0x1a, 0x42, 0x25, 0xb1, 0x81, 0x0d, 0x37, - 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x89, 0x5a, 0x1d, 0x73, 0x72, 0x00, 0x00, 0x00, +func init() { file_proto_common_proto_init() } +func file_proto_common_proto_init() { + if File_proto_common_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_common_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetArticle); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_common_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_proto_common_proto_goTypes, + DependencyIndexes: file_proto_common_proto_depIdxs, + MessageInfos: file_proto_common_proto_msgTypes, + }.Build() + File_proto_common_proto = out.File + file_proto_common_proto_rawDesc = nil + file_proto_common_proto_goTypes = nil + file_proto_common_proto_depIdxs = nil } diff --git a/examples/import/output/output.go b/examples/import/output/output.go index e651cda9..b51b6d00 100644 --- a/examples/import/output/output.go +++ b/examples/import/output/output.go @@ -2,25 +2,39 @@ package company import ( - "context" - "moul.io/protoc-gen-gotemplate/examples/import/output/models/article" - "moul.io/protoc-gen-gotemplate/examples/import/output/models/common" + "moul.io/protoc-gen-gotemplate/examples/import/output/models/common" ) type Repository interface { - GetArticle(getarticle *common.GetArticle) (*company.Article, []*company.Storage, error) + GetArticle(getarticle *common.GetArticle ) (*company.Article, []*company.Storage, error) } + + + + + + // ------------------------- Public SDK ----------------------------- + + + + + + // GetArticle : proto: missing extension proto: missing extension -func (sdk *Sdk) GetArticle(ctx context.Context, - getarticle *article.GetArticle, token, requestID string) (article *article.Article, storages []*article.GetArticleResponse_Storage, err error) { +func (sdk *Sdk) GetArticle(ctx context.Context, + getarticle *article.GetArticle, token, requestID string)(article *article.Article, storages []*article.GetArticleResponse_Storage, err error) { - out := &pb.GetArticleResponse{} + out := &pb.GetArticleResponse{} _ = out - return out.Article, out.Storages, nil + return out.Article, out.Storages, nil + } + + + diff --git a/examples/sitemap/sitemap.xml b/examples/sitemap/sitemap.xml index 9c6bc279..14c153d9 100644 --- a/examples/sitemap/sitemap.xml +++ b/examples/sitemap/sitemap.xml @@ -4,18 +4,18 @@ /posts 0.5 monthly - 2017-05-19 + 2021-04-12 /authors 0.5 monthly - 2017-05-19 + 2021-04-12 /comments 0.5 monthly - 2017-05-19 + 2021-04-12 diff --git a/examples/time/output/time.go b/examples/time/output/time.go index 56b63865..40d3533a 100644 --- a/examples/time/output/time.go +++ b/examples/time/output/time.go @@ -2,9 +2,9 @@ package foo import ( - "github.com/golang/protobuf/ptypes/timestamp" + "github.com/golang/protobuf/ptypes/timestamp" ) type Repository interface { - GetFoo(timestamp *timestamp.Timestamp) (*timestamp.Timestamp, error) -} + GetFoo(timestamp *timestamp.Timestamp ) (string, error) +} \ No newline at end of file diff --git a/encoder.go b/helpers/encoders.go similarity index 94% rename from encoder.go rename to helpers/encoders.go index 3742886b..b584952d 100644 --- a/encoder.go +++ b/helpers/encoders.go @@ -1,4 +1,4 @@ -package main +package pgghelpers import ( "bytes" @@ -12,8 +12,6 @@ import ( "github.com/golang/protobuf/protoc-gen-go/descriptor" plugin_go "github.com/golang/protobuf/protoc-gen-go/plugin" - - pgghelpers "moul.io/protoc-gen-gotemplate/helpers" ) type GenericTemplateBasedEncoder struct { @@ -53,7 +51,7 @@ func NewGenericServiceTemplateBasedEncoder(templateDir string, service *descript if debug { log.Printf("new encoder: file=%q service=%q template-dir=%q", file.GetName(), service.GetName(), templateDir) } - pgghelpers.InitPathMap(file) + InitPathMap(file) return } @@ -70,7 +68,7 @@ func NewGenericTemplateBasedEncoder(templateDir string, file *descriptor.FileDes if debug { log.Printf("new encoder: file=%q template-dir=%q", file.GetName(), templateDir) } - pgghelpers.InitPathMap(file) + InitPathMap(file) return } @@ -145,7 +143,7 @@ func (e *GenericTemplateBasedEncoder) genAst(templateFilename string) (*Ast, err templateFilename = unescaped } - tmpl, err := template.New("").Funcs(pgghelpers.ProtoHelpersFuncMap).Parse(templateFilename) + tmpl, err := template.New("").Funcs(ProtoHelpersFuncMap).Parse(templateFilename) if err != nil { return nil, err } @@ -160,7 +158,7 @@ func (e *GenericTemplateBasedEncoder) buildContent(templateFilename string) (str // initialize template engine fullPath := filepath.Join(e.templateDir, templateFilename) templateName := filepath.Base(fullPath) - tmpl, err := template.New(templateName).Funcs(pgghelpers.ProtoHelpersFuncMap).ParseFiles(fullPath) + tmpl, err := template.New(templateName).Funcs(ProtoHelpersFuncMap).ParseFiles(fullPath) if err != nil { return "", "", err } diff --git a/helpers/parametars.go b/helpers/parametars.go new file mode 100644 index 00000000..46b76927 --- /dev/null +++ b/helpers/parametars.go @@ -0,0 +1,132 @@ +package pgghelpers + +import ( + "log" + "strings" + + "github.com/golang/protobuf/protoc-gen-go/generator" + plugin_go "github.com/golang/protobuf/protoc-gen-go/plugin" + ggdescriptor "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor" +) + +const ( + boolTrue = "true" + boolFalse = "false" +) + +type Parameters struct { + TemplateDir string + DestinationDir string + Debug bool + All bool + SinglePackageMode bool + FileMode bool +} + +func ParseParams(g *generator.Generator) { + + var params Parameters + + if parameter := g.Request.GetParameter(); parameter != "" { + for _, param := range strings.Split(parameter, ",") { + parts := strings.Split(param, "=") + if len(parts) != 2 { + log.Printf("Err: invalid parameter: %q", param) + continue + } + switch parts[0] { + case "template_dir": + params.TemplateDir = parts[1] + case "destination_dir": + params.DestinationDir = parts[1] + case "single-package-mode": + switch strings.ToLower(parts[1]) { + case boolTrue, "t": + params.SinglePackageMode = true + case boolFalse, "f": + default: + log.Printf("Err: invalid value for single-package-mode: %q", parts[1]) + } + case "debug": + switch strings.ToLower(parts[1]) { + case boolTrue, "t": + params.Debug = true + case boolFalse, "f": + default: + log.Printf("Err: invalid value for debug: %q", parts[1]) + } + case "all": + switch strings.ToLower(parts[1]) { + case boolTrue, "t": + params.All = true + case boolFalse, "f": + default: + log.Printf("Err: invalid value for debug: %q", parts[1]) + } + case "file-mode": + switch strings.ToLower(parts[1]) { + case boolTrue, "t": + params.FileMode = true + case boolFalse, "f": + default: + log.Printf("Err: invalid value for file-mode: %q", parts[1]) + } + default: + log.Printf("Err: unknown parameter: %q", param) + } + } + } + + tmplMap := make(map[string]*plugin_go.CodeGeneratorResponse_File) + concatOrAppend := func(file *plugin_go.CodeGeneratorResponse_File) { + if val, ok := tmplMap[file.GetName()]; ok { + *val.Content += file.GetContent() + } else { + tmplMap[file.GetName()] = file + g.Response.File = append(g.Response.File, file) + } + } + + if params.SinglePackageMode { + registry = ggdescriptor.NewRegistry() + SetRegistry(registry) + if err := registry.Load(g.Request); err != nil { + g.Error(err, "registry: failed to load the request") + } + } + + // Generate the encoders + for _, file := range g.Request.GetProtoFile() { + if params.All { + if params.SinglePackageMode { + if _, err := registry.LookupFile(file.GetName()); err != nil { + g.Error(err, "registry: failed to lookup file %q", file.GetName()) + } + } + encoder := NewGenericTemplateBasedEncoder(params.TemplateDir, file, params.Debug, params.DestinationDir) + for _, tmpl := range encoder.Files() { + concatOrAppend(tmpl) + } + + continue + } + + if params.FileMode { + if s := file.GetService(); s != nil && len(s) > 0 { + encoder := NewGenericTemplateBasedEncoder(params.TemplateDir, file, params.Debug, params.DestinationDir) + for _, tmpl := range encoder.Files() { + concatOrAppend(tmpl) + } + } + + continue + } + + for _, service := range file.GetService() { + encoder := NewGenericServiceTemplateBasedEncoder(params.TemplateDir, service, file, params.Debug, params.DestinationDir) + for _, tmpl := range encoder.Files() { + concatOrAppend(tmpl) + } + } + } +} diff --git a/main.go b/main.go index 73e80177..79502c08 100644 --- a/main.go +++ b/main.go @@ -2,27 +2,14 @@ package main // import "moul.io/protoc-gen-gotemplate" import ( "io/ioutil" - "log" "os" - "strings" "github.com/golang/protobuf/proto" "github.com/golang/protobuf/protoc-gen-go/generator" - plugin_go "github.com/golang/protobuf/protoc-gen-go/plugin" - ggdescriptor "github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor" pgghelpers "moul.io/protoc-gen-gotemplate/helpers" ) -var ( - registry *ggdescriptor.Registry // some helpers need access to registry -) - -const ( - boolTrue = "true" - boolFalse = "false" -) - func main() { g := generator.New() @@ -41,117 +28,7 @@ func main() { g.CommandLineParameters(g.Request.GetParameter()) - // Parse parameters - var ( - templateDir = "./templates" - destinationDir = "." - debug = false - all = false - singlePackageMode = false - fileMode = false - ) - if parameter := g.Request.GetParameter(); parameter != "" { - for _, param := range strings.Split(parameter, ",") { - parts := strings.Split(param, "=") - if len(parts) != 2 { - log.Printf("Err: invalid parameter: %q", param) - continue - } - switch parts[0] { - case "template_dir": - templateDir = parts[1] - case "destination_dir": - destinationDir = parts[1] - case "single-package-mode": - switch strings.ToLower(parts[1]) { - case boolTrue, "t": - singlePackageMode = true - case boolFalse, "f": - default: - log.Printf("Err: invalid value for single-package-mode: %q", parts[1]) - } - case "debug": - switch strings.ToLower(parts[1]) { - case boolTrue, "t": - debug = true - case boolFalse, "f": - default: - log.Printf("Err: invalid value for debug: %q", parts[1]) - } - case "all": - switch strings.ToLower(parts[1]) { - case boolTrue, "t": - all = true - case boolFalse, "f": - default: - log.Printf("Err: invalid value for debug: %q", parts[1]) - } - case "file-mode": - switch strings.ToLower(parts[1]) { - case boolTrue, "t": - fileMode = true - case boolFalse, "f": - default: - log.Printf("Err: invalid value for file-mode: %q", parts[1]) - } - default: - log.Printf("Err: unknown parameter: %q", param) - } - } - } - - tmplMap := make(map[string]*plugin_go.CodeGeneratorResponse_File) - concatOrAppend := func(file *plugin_go.CodeGeneratorResponse_File) { - if val, ok := tmplMap[file.GetName()]; ok { - *val.Content += file.GetContent() - } else { - tmplMap[file.GetName()] = file - g.Response.File = append(g.Response.File, file) - } - } - - if singlePackageMode { - registry = ggdescriptor.NewRegistry() - pgghelpers.SetRegistry(registry) - if err = registry.Load(g.Request); err != nil { - g.Error(err, "registry: failed to load the request") - } - } - - // Generate the encoders - for _, file := range g.Request.GetProtoFile() { - if all { - if singlePackageMode { - if _, err = registry.LookupFile(file.GetName()); err != nil { - g.Error(err, "registry: failed to lookup file %q", file.GetName()) - } - } - encoder := NewGenericTemplateBasedEncoder(templateDir, file, debug, destinationDir) - for _, tmpl := range encoder.Files() { - concatOrAppend(tmpl) - } - - continue - } - - if fileMode { - if s := file.GetService(); s != nil && len(s) > 0 { - encoder := NewGenericTemplateBasedEncoder(templateDir, file, debug, destinationDir) - for _, tmpl := range encoder.Files() { - concatOrAppend(tmpl) - } - } - - continue - } - - for _, service := range file.GetService() { - encoder := NewGenericServiceTemplateBasedEncoder(templateDir, service, file, debug, destinationDir) - for _, tmpl := range encoder.Files() { - concatOrAppend(tmpl) - } - } - } + pgghelpers.ParseParams(g) // Generate the protobufs g.GenerateAllFiles()