protoc-gen-go-micro/rpc.go
Vasiliy Tolstov b002cbb491 fixup imports
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2021-02-24 01:20:52 +03:00

40 lines
992 B
Go

package main
import (
"google.golang.org/protobuf/compiler/protogen"
)
func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin) error {
for _, file := range plugin.Files {
if !file.Generate {
continue
}
if len(file.Services) == 0 {
continue
}
gname := file.GeneratedFilenamePrefix + "_micro_" + component + ".pb.go"
gfile := plugin.NewGeneratedFile(gname, file.GoImportPath)
gfile.P("// Code generated by protoc-gen-micro")
gfile.P("// source: ", *file.Proto.Name)
gfile.P("package ", file.GoPackageName)
gfile.P()
gfile.Import(contextPackage)
gfile.Import(microApiPackage)
gfile.Import(microClientPackage)
gfile.Import(microServerPackage)
for _, service := range file.Services {
generateServiceClient(gfile, service)
generateServiceClientMethods(gfile, service, false)
generateServiceServer(gfile, service)
generateServiceServerMethods(gfile, service)
generateServiceRegister(gfile, service)
}
}
return nil
}