2021-02-22 18:11:08 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"google.golang.org/protobuf/compiler/protogen"
|
|
|
|
)
|
|
|
|
|
2021-03-26 15:00:55 +03:00
|
|
|
func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genClient bool, genServer bool) error {
|
2021-02-22 18:11:08 +03:00
|
|
|
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
|
|
|
|
2021-06-22 01:34:06 +03:00
|
|
|
gfile.P("// Code generated by protoc-gen-go-micro. DO NOT EDIT.")
|
|
|
|
gfile.P("// protoc-gen-go-micro version: " + versionComment)
|
2021-05-08 00:06:40 +03:00
|
|
|
gfile.P("// source: ", file.Proto.GetName())
|
2021-06-23 00:23:38 +03:00
|
|
|
gfile.P()
|
2021-02-23 03:04:56 +03:00
|
|
|
gfile.P("package ", file.GoPackageName)
|
|
|
|
gfile.P()
|
|
|
|
|
2021-02-23 23:58:24 +03:00
|
|
|
gfile.Import(contextPackage)
|
|
|
|
gfile.Import(microApiPackage)
|
2021-03-26 15:00:55 +03:00
|
|
|
if genClient {
|
|
|
|
gfile.Import(microClientPackage)
|
|
|
|
}
|
|
|
|
if genServer {
|
|
|
|
gfile.Import(microServerPackage)
|
|
|
|
}
|
2021-02-23 03:04:56 +03:00
|
|
|
for _, service := range file.Services {
|
2021-03-26 15:00:55 +03:00
|
|
|
if genClient {
|
2022-03-19 15:13:34 +03:00
|
|
|
g.generateServiceClient(gfile, service)
|
2022-03-20 15:08:04 +03:00
|
|
|
g.generateServiceClientMethods(gfile, service, component)
|
2021-03-26 15:00:55 +03:00
|
|
|
}
|
|
|
|
if genServer {
|
|
|
|
generateServiceServer(gfile, service)
|
2022-03-19 15:13:34 +03:00
|
|
|
g.generateServiceServerMethods(gfile, service)
|
|
|
|
g.generateServiceRegister(gfile, service)
|
2021-03-26 15:00:55 +03:00
|
|
|
}
|
2022-11-15 12:53:04 +03:00
|
|
|
if component == "grpc" && g.reflection {
|
|
|
|
g.generateServiceDesc(gfile, file, service)
|
|
|
|
}
|
2021-02-23 03:04:56 +03:00
|
|
|
}
|
2021-02-22 18:11:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|