Skip to content

Commit

Permalink
Merge pull request #655 from noice-com/dev
Browse files Browse the repository at this point in the history
Prevent grain protogen from trying to generate code for includes
  • Loading branch information
rogeralsing authored Apr 22, 2022
2 parents 118bd5f + 7dfc715 commit 358d18a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions protobuf/protoc-gen-gograinv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 358d18a

Please sign in to comment.