Skip to content

Commit

Permalink
Remove var for method descriptors
Browse files Browse the repository at this point in the history
Signed-off-by: Edward McFarlane <[email protected]>
  • Loading branch information
emcfarlane committed Dec 19, 2024
1 parent c71a431 commit 70ee2a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
14 changes: 5 additions & 9 deletions cmd/protoc-gen-connect-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,14 @@ func generateServiceNameConstants(g *protogen.GeneratedFile, services []*protoge
g.P()
}

func generateServiceNameVariables(g *protogen.GeneratedFile, file *protogen.File, service *protogen.Service) {
func generateServiceMethodsVar(g *protogen.GeneratedFile, file *protogen.File, service *protogen.Service) {
if len(service.Methods) == 0 {
return
}
serviceMethodsName := unexport(fmt.Sprintf("%sMethods", service.Desc.Name()))
g.P(serviceMethodsName, ` := `,
g.QualifiedGoIdent(file.GoDescriptorIdent),
`.Services().ByName("`, service.Desc.Name(), `").Methods()`)
for _, method := range service.Methods {
g.P(procedureVarMethodDescriptor(method), ` := `,
serviceMethodsName,
`.ByName("`, method.Desc.Name(), `")`)
}
}

func generateService(g *protogen.GeneratedFile, file *protogen.File, service *protogen.Service) {
Expand Down Expand Up @@ -289,7 +284,7 @@ func generateClientImplementation(g *protogen.GeneratedFile, file *protogen.File
if len(service.Methods) > 0 {
g.P("baseURL = ", stringsPackage.Ident("TrimRight"), `(baseURL, "/")`)
}
generateServiceNameVariables(g, file, service)
generateServiceMethodsVar(g, file, service)
g.P("return &", names.ClientImpl, "{")
for _, method := range service.Methods {
g.P(unexport(method.GoName), ": ",
Expand Down Expand Up @@ -418,7 +413,7 @@ func generateServerConstructor(g *protogen.GeneratedFile, file *protogen.File, s
handlerOption := connectPackage.Ident("HandlerOption")
g.P("func ", names.ServerConstructor, "(svc ", names.Server, ", opts ...", handlerOption,
") (string, ", httpPackage.Ident("Handler"), ") {")
generateServiceNameVariables(g, file, service)
generateServiceMethodsVar(g, file, service)
for _, method := range service.Methods {
isStreamingServer := method.Desc.IsStreamingServer()
isStreamingClient := method.Desc.IsStreamingClient()
Expand Down Expand Up @@ -532,7 +527,8 @@ func procedureHandlerName(m *protogen.Method) string {
}

func procedureVarMethodDescriptor(m *protogen.Method) string {
return unexport(fmt.Sprintf("%s%sMethodDescriptor", m.Parent.GoName, m.GoName))
serviceMethodsName := unexport(fmt.Sprintf("%sMethods", m.Parent.GoName))
return serviceMethodsName + `.ByName("` + string(m.Desc.Name()) + `")`
}

func isDeprecatedService(service *protogen.Service) bool {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 10 additions & 20 deletions internal/gen/connect/ping/v1/pingv1connect/ping.connect.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70ee2a2

Please sign in to comment.