MCPcopy
hub / github.com/golang/protobuf / genService

Function genService

internal/gengogrpc/grpc.go:61–203  ·  view source on GitHub ↗
(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service)

Source from the content-addressed store, hash-verified

59}
60
61func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service) {
62 clientName := service.GoName + "Client"
63
64 g.P("// ", clientName, " is the client API for ", service.GoName, " service.")
65 g.P("//")
66 g.P("// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.")
67
68 // Client interface.
69 if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {
70 g.P("//")
71 g.P(deprecationComment)
72 }
73 g.Annotate(clientName, service.Location)
74 g.P("type ", clientName, " interface {")
75 for _, method := range service.Methods {
76 g.Annotate(clientName+"."+method.GoName, method.Location)
77 if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() {
78 g.P(deprecationComment)
79 }
80 g.P(method.Comments.Leading,
81 clientSignature(g, method))
82 }
83 g.P("}")
84 g.P()
85
86 // Client structure.
87 g.P("type ", unexport(clientName), " struct {")
88 g.P("cc ", grpcPackage.Ident("ClientConnInterface"))
89 g.P("}")
90 g.P()
91
92 // NewClient factory.
93 if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {
94 g.P(deprecationComment)
95 }
96 g.P("func New", clientName, " (cc ", grpcPackage.Ident("ClientConnInterface"), ") ", clientName, " {")
97 g.P("return &", unexport(clientName), "{cc}")
98 g.P("}")
99 g.P()
100
101 var methodIndex, streamIndex int
102 // Client method implementations.
103 for _, method := range service.Methods {
104 if !method.Desc.IsStreamingServer() && !method.Desc.IsStreamingClient() {
105 // Unary RPC method
106 genClientMethod(gen, file, g, method, methodIndex)
107 methodIndex++
108 } else {
109 // Streaming RPC method
110 genClientMethod(gen, file, g, method, streamIndex)
111 streamIndex++
112 }
113 }
114
115 // Server interface.
116 serverType := service.GoName + "Server"
117 g.P("// ", serverType, " is the server API for ", service.GoName, " service.")
118 if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {

Callers 1

GenerateFileContentFunction · 0.85

Calls 7

clientSignatureFunction · 0.85
genClientMethodFunction · 0.85
serverSignatureFunction · 0.85
genServerMethodFunction · 0.85
unexportFunction · 0.70
NameMethod · 0.65
PMethod · 0.45

Tested by

no test coverage detected