(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service)
| 59 | } |
| 60 | |
| 61 | func 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() { |
no test coverage detected