Only generate a Go file if the file has some services

Otherwise, this generator creates a Go file with some import statements,
that causes "imported and not used" error.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
Kazuyoshi Kato 2022-04-19 17:09:21 +00:00
parent aa5c94700b
commit f0fda535e2

View File

@ -58,6 +58,11 @@ func newGenerator(out *protogen.GeneratedFile) *generator {
}
func generate(plugin *protogen.Plugin, input *protogen.File) error {
if len(input.Services) == 0 {
// Only generate a Go file if the file has some services.
return nil
}
file := plugin.NewGeneratedFile(input.GeneratedFilenamePrefix+"_ttrpc.pb.go", input.GoImportPath)
file.P("// Code generated by protoc-gen-go-ttrpc. DO NOT EDIT.")
file.P("// source: ", input.Desc.Path())