fix drpc method name in generator

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2022-03-20 15:08:04 +03:00
parent 03355d0d83
commit a2fea36f50
4 changed files with 8 additions and 5 deletions

View File

@ -41,7 +41,7 @@ func (g *Generator) httpGenerate(component string, plugin *protogen.Plugin, genC
for _, service := range file.Services {
if genClient {
g.generateServiceClient(gfile, service)
g.generateServiceClientMethods(gfile, service, true)
g.generateServiceClientMethods(gfile, service, component)
}
if genServer {
generateServiceServer(gfile, service)

View File

@ -90,7 +90,7 @@ func (g *Generator) Generate(plugin *protogen.Plugin) error {
case "http":
err = g.httpGenerate(component, plugin, genClient, genServer)
case "grpc", "drpc", "rpc":
err = g.rpcGenerate("rpc", plugin, genClient, genServer)
err = g.rpcGenerate(component, plugin, genClient, genServer)
case "gorilla":
err = g.gorillaGenerate(component, plugin)
case "chi":

2
rpc.go
View File

@ -38,7 +38,7 @@ func (g *Generator) rpcGenerate(component string, plugin *protogen.Plugin, genCl
for _, service := range file.Services {
if genClient {
g.generateServiceClient(gfile, service)
g.generateServiceClientMethods(gfile, service, false)
g.generateServiceClientMethods(gfile, service, component)
}
if genServer {
generateServiceServer(gfile, service)

View File

@ -45,13 +45,16 @@ func (g *Generator) generateServiceClient(gfile *protogen.GeneratedFile, service
gfile.P()
}
func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protogen.Service, http bool) {
func (g *Generator) generateServiceClientMethods(gfile *protogen.GeneratedFile, service *protogen.Service, component string) {
serviceName := service.GoName
for _, method := range service.Methods {
methodName := fmt.Sprintf("%s.%s", serviceName, method.GoName)
if component == "drpc" {
methodName = fmt.Sprintf("%s.%s", method.Parent.Desc.FullName(), method.Desc.Name())
}
g.generateClientFuncSignature(gfile, serviceName, method)
if http && method.Desc.Options() != nil {
if component == "http" && method.Desc.Options() != nil {
if proto.HasExtension(method.Desc.Options(), v2.E_Openapiv2Operation) {
opts := proto.GetExtension(method.Desc.Options(), v2.E_Openapiv2Operation)
if opts != nil {