Skip to content

Commit

Permalink
don't duplicate 'handler' interface if proto file contains multiple s…
Browse files Browse the repository at this point in the history
…ervices (#22)
  • Loading branch information
actatum authored Jun 24, 2024
1 parent 24a08c3 commit cb51dd6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions internal/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func GenerateFileContent(file *protogen.File, g *protogen.GeneratedFile) {
for _, service := range file.Services {
genService(g, service)
}
genHandlerInterface(g)
}

func genService(g *protogen.GeneratedFile, service *protogen.Service) {
Expand Down Expand Up @@ -129,13 +130,6 @@ func genService(g *protogen.GeneratedFile, service *protogen.Service) {
handlerNames = append(handlerNames, hname)
}

// Handlers
g.P("type handler interface {")
g.P("Route() string")
g.P("HandlerFunc() stormrpc.HandlerFunc")
g.P("SetService(interface{})")
g.P("}")

// HandlerFuncs
g.P("var ", unexport(service.GoName), "Handlers = []handler{")
for i, method := range service.Methods {
Expand All @@ -145,6 +139,14 @@ func genService(g *protogen.GeneratedFile, service *protogen.Service) {
g.P()
}

func genHandlerInterface(g *protogen.GeneratedFile) {
g.P("type handler interface {")
g.P("Route() string")
g.P("HandlerFunc() stormrpc.HandlerFunc")
g.P("SetService(interface{})")
g.P("}")
}

func clientSignature(g *protogen.GeneratedFile, method *protogen.Method) string {
s := method.GoName + "(ctx " + g.QualifiedGoIdent(contextPackage.Ident("Context"))
if !method.Desc.IsStreamingClient() {
Expand Down
2 changes: 1 addition & 1 deletion prototest/test.pb.go

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

2 changes: 1 addition & 1 deletion prototest/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ message HelloRequest {

message HelloReply {
string message = 1;
}
}

0 comments on commit cb51dd6

Please sign in to comment.