From 759e5f38aed0ca6bc7562c86b3ff0f5f73839b0d Mon Sep 17 00:00:00 2001 From: orktes Date: Fri, 22 Apr 2022 10:11:38 +0300 Subject: [PATCH 1/2] Check req.FileToGenerate before generating a file --- protobuf/protoc-gen-gograinv2/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/protobuf/protoc-gen-gograinv2/main.go b/protobuf/protoc-gen-gograinv2/main.go index 641abfcbf..11b53bc7f 100644 --- a/protobuf/protoc-gen-gograinv2/main.go +++ b/protobuf/protoc-gen-gograinv2/main.go @@ -23,6 +23,10 @@ func removePackagePrefix(name string, pname string) string { func generateCode(req *plugin.CodeGeneratorRequest, filenameSuffix string, goFmt bool) *plugin.CodeGeneratorResponse { response := &plugin.CodeGeneratorResponse{} for _, f := range req.GetProtoFile() { + if inStringSlice(f.GetName(), req.FileToGenerate) { + continue + } + s := generate(f) // we only generate grains for proto files containing valid service definition @@ -40,6 +44,15 @@ func generateCode(req *plugin.CodeGeneratorRequest, filenameSuffix string, goFmt return response } +func inStringSlice(val string, ss []string) bool { + for _, s := range ss { + if val == s { + return true + } + } + return false +} + func generate(file *google_protobuf.FileDescriptorProto) string { pkg := ProtoAst(file) From 7dfc715aa9f32b1f792cfccbf771f9451783a925 Mon Sep 17 00:00:00 2001 From: orktes Date: Fri, 22 Apr 2022 10:13:26 +0300 Subject: [PATCH 2/2] Fix condition for FileToGenerate check --- protobuf/protoc-gen-gograinv2/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf/protoc-gen-gograinv2/main.go b/protobuf/protoc-gen-gograinv2/main.go index 11b53bc7f..00c71fef6 100644 --- a/protobuf/protoc-gen-gograinv2/main.go +++ b/protobuf/protoc-gen-gograinv2/main.go @@ -23,7 +23,7 @@ func removePackagePrefix(name string, pname string) string { func generateCode(req *plugin.CodeGeneratorRequest, filenameSuffix string, goFmt bool) *plugin.CodeGeneratorResponse { response := &plugin.CodeGeneratorResponse{} for _, f := range req.GetProtoFile() { - if inStringSlice(f.GetName(), req.FileToGenerate) { + if !inStringSlice(f.GetName(), req.FileToGenerate) { continue }