2021-02-22 18:11:08 +03:00
|
|
|
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
|
|
|
|
}
|
2021-02-23 03:04:56 +03:00
|
|
|
if len(file.Services) == 0 {
|
|
|
|
continue
|
2021-02-22 18:11:08 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 14:30:23 +03:00
|
|
|
gname := file.GeneratedFilenamePrefix + "_micro_" + component + ".pb.go"
|
2021-02-25 14:19:09 +03:00
|
|
|
path := file.GoImportPath
|
|
|
|
if g.standalone {
|
|
|
|
path = "."
|
|
|
|
}
|
|
|
|
gfile := plugin.NewGeneratedFile(gname, path)
|
2021-02-23 03:04:56 +03:00
|
|
|
|
|
|
|
gfile.P("// Code generated by protoc-gen-micro")
|
|
|
|
gfile.P("// source: ", *file.Proto.Name)
|
|
|
|
gfile.P("package ", file.GoPackageName)
|
|
|
|
gfile.P()
|
|
|
|
|
2021-02-23 23:58:24 +03:00
|
|
|
gfile.Import(contextPackage)
|
|
|
|
gfile.Import(microApiPackage)
|
|
|
|
gfile.Import(microClientPackage)
|
|
|
|
gfile.Import(microServerPackage)
|
2021-02-23 03:04:56 +03:00
|
|
|
|
|
|
|
for _, service := range file.Services {
|
|
|
|
generateServiceClient(gfile, service)
|
|
|
|
generateServiceClientMethods(gfile, service, false)
|
|
|
|
generateServiceServer(gfile, service)
|
|
|
|
generateServiceServerMethods(gfile, service)
|
|
|
|
generateServiceRegister(gfile, service)
|
|
|
|
}
|
2021-02-22 18:11:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|