From 8ac3eecc2bcf1f9ecfa64108b3f8dcb8e45deea6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:59:55 +0000 Subject: [PATCH 1/2] vendor: Bump google.golang.org/grpc/cmd/protoc-gen-go-grpc Bumps [google.golang.org/grpc/cmd/protoc-gen-go-grpc](https://github.com/grpc/grpc-go) from 1.2.0 to 1.3.0. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.2.0...v1.3.0) --- updated-dependencies: - dependency-name: google.golang.org/grpc/cmd/protoc-gen-go-grpc dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- internal/proto/networkfence_grpc.pb.go | 15 +- internal/proto/reclaimspace_grpc.pb.go | 15 +- internal/proto/replication_grpc.pb.go | 35 ++- .../grpc/cmd/protoc-gen-go-grpc/grpc.go | 236 ++++++++++++------ .../grpc/cmd/protoc-gen-go-grpc/main.go | 5 +- vendor/modules.txt | 4 +- 8 files changed, 212 insertions(+), 104 deletions(-) diff --git a/go.mod b/go.mod index ead87ab67..45f04d762 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/stretchr/testify v1.8.2 go.uber.org/zap v1.24.0 google.golang.org/grpc v1.53.0 - google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 + google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 google.golang.org/protobuf v1.28.1 k8s.io/api v0.26.2 k8s.io/apimachinery v0.26.2 diff --git a/go.sum b/go.sum index 258c160dc..cdc8fc875 100644 --- a/go.sum +++ b/go.sum @@ -1864,8 +1864,8 @@ google.golang.org/grpc v1.43.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ5 google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 h1:TLkBREm4nIsEcexnCjgQd5GQWaHcqMzwQV0TX9pq8S0= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/internal/proto/networkfence_grpc.pb.go b/internal/proto/networkfence_grpc.pb.go index b6a0d6bf2..12d21258c 100644 --- a/internal/proto/networkfence_grpc.pb.go +++ b/internal/proto/networkfence_grpc.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.2.0 +// - protoc-gen-go-grpc v1.3.0 // - protoc v3.19.6 // source: networkfence.proto @@ -18,6 +18,11 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 +const ( + NetworkFence_FenceClusterNetwork_FullMethodName = "/proto.NetworkFence/FenceClusterNetwork" + NetworkFence_UnFenceClusterNetwork_FullMethodName = "/proto.NetworkFence/UnFenceClusterNetwork" +) + // NetworkFenceClient is the client API for NetworkFence service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. @@ -38,7 +43,7 @@ func NewNetworkFenceClient(cc grpc.ClientConnInterface) NetworkFenceClient { func (c *networkFenceClient) FenceClusterNetwork(ctx context.Context, in *NetworkFenceRequest, opts ...grpc.CallOption) (*NetworkFenceResponse, error) { out := new(NetworkFenceResponse) - err := c.cc.Invoke(ctx, "/proto.NetworkFence/FenceClusterNetwork", in, out, opts...) + err := c.cc.Invoke(ctx, NetworkFence_FenceClusterNetwork_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -47,7 +52,7 @@ func (c *networkFenceClient) FenceClusterNetwork(ctx context.Context, in *Networ func (c *networkFenceClient) UnFenceClusterNetwork(ctx context.Context, in *NetworkFenceRequest, opts ...grpc.CallOption) (*NetworkFenceResponse, error) { out := new(NetworkFenceResponse) - err := c.cc.Invoke(ctx, "/proto.NetworkFence/UnFenceClusterNetwork", in, out, opts...) + err := c.cc.Invoke(ctx, NetworkFence_UnFenceClusterNetwork_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -98,7 +103,7 @@ func _NetworkFence_FenceClusterNetwork_Handler(srv interface{}, ctx context.Cont } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.NetworkFence/FenceClusterNetwork", + FullMethod: NetworkFence_FenceClusterNetwork_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(NetworkFenceServer).FenceClusterNetwork(ctx, req.(*NetworkFenceRequest)) @@ -116,7 +121,7 @@ func _NetworkFence_UnFenceClusterNetwork_Handler(srv interface{}, ctx context.Co } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.NetworkFence/UnFenceClusterNetwork", + FullMethod: NetworkFence_UnFenceClusterNetwork_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(NetworkFenceServer).UnFenceClusterNetwork(ctx, req.(*NetworkFenceRequest)) diff --git a/internal/proto/reclaimspace_grpc.pb.go b/internal/proto/reclaimspace_grpc.pb.go index 192082b07..459f01682 100644 --- a/internal/proto/reclaimspace_grpc.pb.go +++ b/internal/proto/reclaimspace_grpc.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.2.0 +// - protoc-gen-go-grpc v1.3.0 // - protoc v3.19.6 // source: reclaimspace.proto @@ -18,6 +18,11 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 +const ( + ReclaimSpace_ControllerReclaimSpace_FullMethodName = "/proto.ReclaimSpace/ControllerReclaimSpace" + ReclaimSpace_NodeReclaimSpace_FullMethodName = "/proto.ReclaimSpace/NodeReclaimSpace" +) + // ReclaimSpaceClient is the client API for ReclaimSpace service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. @@ -40,7 +45,7 @@ func NewReclaimSpaceClient(cc grpc.ClientConnInterface) ReclaimSpaceClient { func (c *reclaimSpaceClient) ControllerReclaimSpace(ctx context.Context, in *ReclaimSpaceRequest, opts ...grpc.CallOption) (*ReclaimSpaceResponse, error) { out := new(ReclaimSpaceResponse) - err := c.cc.Invoke(ctx, "/proto.ReclaimSpace/ControllerReclaimSpace", in, out, opts...) + err := c.cc.Invoke(ctx, ReclaimSpace_ControllerReclaimSpace_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -49,7 +54,7 @@ func (c *reclaimSpaceClient) ControllerReclaimSpace(ctx context.Context, in *Rec func (c *reclaimSpaceClient) NodeReclaimSpace(ctx context.Context, in *ReclaimSpaceRequest, opts ...grpc.CallOption) (*ReclaimSpaceResponse, error) { out := new(ReclaimSpaceResponse) - err := c.cc.Invoke(ctx, "/proto.ReclaimSpace/NodeReclaimSpace", in, out, opts...) + err := c.cc.Invoke(ctx, ReclaimSpace_NodeReclaimSpace_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -102,7 +107,7 @@ func _ReclaimSpace_ControllerReclaimSpace_Handler(srv interface{}, ctx context.C } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.ReclaimSpace/ControllerReclaimSpace", + FullMethod: ReclaimSpace_ControllerReclaimSpace_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReclaimSpaceServer).ControllerReclaimSpace(ctx, req.(*ReclaimSpaceRequest)) @@ -120,7 +125,7 @@ func _ReclaimSpace_NodeReclaimSpace_Handler(srv interface{}, ctx context.Context } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.ReclaimSpace/NodeReclaimSpace", + FullMethod: ReclaimSpace_NodeReclaimSpace_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReclaimSpaceServer).NodeReclaimSpace(ctx, req.(*ReclaimSpaceRequest)) diff --git a/internal/proto/replication_grpc.pb.go b/internal/proto/replication_grpc.pb.go index 148e4e676..41e8e7fb6 100644 --- a/internal/proto/replication_grpc.pb.go +++ b/internal/proto/replication_grpc.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.2.0 +// - protoc-gen-go-grpc v1.3.0 // - protoc v3.19.6 // source: replication.proto @@ -18,6 +18,15 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 +const ( + Replication_EnableVolumeReplication_FullMethodName = "/proto.Replication/EnableVolumeReplication" + Replication_DisableVolumeReplication_FullMethodName = "/proto.Replication/DisableVolumeReplication" + Replication_PromoteVolume_FullMethodName = "/proto.Replication/PromoteVolume" + Replication_DemoteVolume_FullMethodName = "/proto.Replication/DemoteVolume" + Replication_ResyncVolume_FullMethodName = "/proto.Replication/ResyncVolume" + Replication_GetVolumeReplicationInfo_FullMethodName = "/proto.Replication/GetVolumeReplicationInfo" +) + // ReplicationClient is the client API for Replication service. // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. @@ -46,7 +55,7 @@ func NewReplicationClient(cc grpc.ClientConnInterface) ReplicationClient { func (c *replicationClient) EnableVolumeReplication(ctx context.Context, in *EnableVolumeReplicationRequest, opts ...grpc.CallOption) (*EnableVolumeReplicationResponse, error) { out := new(EnableVolumeReplicationResponse) - err := c.cc.Invoke(ctx, "/proto.Replication/EnableVolumeReplication", in, out, opts...) + err := c.cc.Invoke(ctx, Replication_EnableVolumeReplication_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -55,7 +64,7 @@ func (c *replicationClient) EnableVolumeReplication(ctx context.Context, in *Ena func (c *replicationClient) DisableVolumeReplication(ctx context.Context, in *DisableVolumeReplicationRequest, opts ...grpc.CallOption) (*DisableVolumeReplicationResponse, error) { out := new(DisableVolumeReplicationResponse) - err := c.cc.Invoke(ctx, "/proto.Replication/DisableVolumeReplication", in, out, opts...) + err := c.cc.Invoke(ctx, Replication_DisableVolumeReplication_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -64,7 +73,7 @@ func (c *replicationClient) DisableVolumeReplication(ctx context.Context, in *Di func (c *replicationClient) PromoteVolume(ctx context.Context, in *PromoteVolumeRequest, opts ...grpc.CallOption) (*PromoteVolumeResponse, error) { out := new(PromoteVolumeResponse) - err := c.cc.Invoke(ctx, "/proto.Replication/PromoteVolume", in, out, opts...) + err := c.cc.Invoke(ctx, Replication_PromoteVolume_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -73,7 +82,7 @@ func (c *replicationClient) PromoteVolume(ctx context.Context, in *PromoteVolume func (c *replicationClient) DemoteVolume(ctx context.Context, in *DemoteVolumeRequest, opts ...grpc.CallOption) (*DemoteVolumeResponse, error) { out := new(DemoteVolumeResponse) - err := c.cc.Invoke(ctx, "/proto.Replication/DemoteVolume", in, out, opts...) + err := c.cc.Invoke(ctx, Replication_DemoteVolume_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -82,7 +91,7 @@ func (c *replicationClient) DemoteVolume(ctx context.Context, in *DemoteVolumeRe func (c *replicationClient) ResyncVolume(ctx context.Context, in *ResyncVolumeRequest, opts ...grpc.CallOption) (*ResyncVolumeResponse, error) { out := new(ResyncVolumeResponse) - err := c.cc.Invoke(ctx, "/proto.Replication/ResyncVolume", in, out, opts...) + err := c.cc.Invoke(ctx, Replication_ResyncVolume_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -91,7 +100,7 @@ func (c *replicationClient) ResyncVolume(ctx context.Context, in *ResyncVolumeRe func (c *replicationClient) GetVolumeReplicationInfo(ctx context.Context, in *GetVolumeReplicationInfoRequest, opts ...grpc.CallOption) (*GetVolumeReplicationInfoResponse, error) { out := new(GetVolumeReplicationInfoResponse) - err := c.cc.Invoke(ctx, "/proto.Replication/GetVolumeReplicationInfo", in, out, opts...) + err := c.cc.Invoke(ctx, Replication_GetVolumeReplicationInfo_FullMethodName, in, out, opts...) if err != nil { return nil, err } @@ -162,7 +171,7 @@ func _Replication_EnableVolumeReplication_Handler(srv interface{}, ctx context.C } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Replication/EnableVolumeReplication", + FullMethod: Replication_EnableVolumeReplication_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReplicationServer).EnableVolumeReplication(ctx, req.(*EnableVolumeReplicationRequest)) @@ -180,7 +189,7 @@ func _Replication_DisableVolumeReplication_Handler(srv interface{}, ctx context. } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Replication/DisableVolumeReplication", + FullMethod: Replication_DisableVolumeReplication_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReplicationServer).DisableVolumeReplication(ctx, req.(*DisableVolumeReplicationRequest)) @@ -198,7 +207,7 @@ func _Replication_PromoteVolume_Handler(srv interface{}, ctx context.Context, de } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Replication/PromoteVolume", + FullMethod: Replication_PromoteVolume_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReplicationServer).PromoteVolume(ctx, req.(*PromoteVolumeRequest)) @@ -216,7 +225,7 @@ func _Replication_DemoteVolume_Handler(srv interface{}, ctx context.Context, dec } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Replication/DemoteVolume", + FullMethod: Replication_DemoteVolume_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReplicationServer).DemoteVolume(ctx, req.(*DemoteVolumeRequest)) @@ -234,7 +243,7 @@ func _Replication_ResyncVolume_Handler(srv interface{}, ctx context.Context, dec } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Replication/ResyncVolume", + FullMethod: Replication_ResyncVolume_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReplicationServer).ResyncVolume(ctx, req.(*ResyncVolumeRequest)) @@ -252,7 +261,7 @@ func _Replication_GetVolumeReplicationInfo_Handler(srv interface{}, ctx context. } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/proto.Replication/GetVolumeReplicationInfo", + FullMethod: Replication_GetVolumeReplicationInfo_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ReplicationServer).GetVolumeReplicationInfo(ctx, req.(*GetVolumeReplicationInfoRequest)) diff --git a/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/grpc.go b/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/grpc.go index f45e0403f..9e15d2d8d 100644 --- a/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/grpc.go +++ b/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/grpc.go @@ -24,6 +24,7 @@ import ( "strings" "google.golang.org/protobuf/compiler/protogen" + "google.golang.org/protobuf/reflect/protoreflect" "google.golang.org/protobuf/types/descriptorpb" ) @@ -34,6 +35,94 @@ const ( statusPackage = protogen.GoImportPath("google.golang.org/grpc/status") ) +type serviceGenerateHelperInterface interface { + formatFullMethodSymbol(service *protogen.Service, method *protogen.Method) string + genFullMethods(g *protogen.GeneratedFile, service *protogen.Service) + generateClientStruct(g *protogen.GeneratedFile, clientName string) + generateNewClientDefinitions(g *protogen.GeneratedFile, service *protogen.Service, clientName string) + generateUnimplementedServerType(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service) + generateServerFunctions(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, serverType string, serviceDescVar string) + formatHandlerFuncName(service *protogen.Service, hname string) string +} + +type serviceGenerateHelper struct{} + +func (serviceGenerateHelper) formatFullMethodSymbol(service *protogen.Service, method *protogen.Method) string { + return fmt.Sprintf("%s_%s_FullMethodName", service.GoName, method.GoName) +} + +func (serviceGenerateHelper) genFullMethods(g *protogen.GeneratedFile, service *protogen.Service) { + g.P("const (") + for _, method := range service.Methods { + fmSymbol := helper.formatFullMethodSymbol(service, method) + fmName := fmt.Sprintf("/%s/%s", service.Desc.FullName(), method.Desc.Name()) + g.P(fmSymbol, ` = "`, fmName, `"`) + } + g.P(")") + g.P() +} + +func (serviceGenerateHelper) generateClientStruct(g *protogen.GeneratedFile, clientName string) { + g.P("type ", unexport(clientName), " struct {") + g.P("cc ", grpcPackage.Ident("ClientConnInterface")) + g.P("}") + g.P() +} + +func (serviceGenerateHelper) generateNewClientDefinitions(g *protogen.GeneratedFile, service *protogen.Service, clientName string) { + g.P("return &", unexport(clientName), "{cc}") +} + +func (serviceGenerateHelper) generateUnimplementedServerType(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service) { + serverType := service.GoName + "Server" + mustOrShould := "must" + if !*requireUnimplemented { + mustOrShould = "should" + } + // Server Unimplemented struct for forward compatibility. + g.P("// Unimplemented", serverType, " ", mustOrShould, " be embedded to have forward compatible implementations.") + g.P("type Unimplemented", serverType, " struct {") + g.P("}") + g.P() + for _, method := range service.Methods { + nilArg := "" + if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { + nilArg = "nil," + } + g.P("func (Unimplemented", serverType, ") ", serverSignature(g, method), "{") + g.P("return ", nilArg, statusPackage.Ident("Errorf"), "(", codesPackage.Ident("Unimplemented"), `, "method `, method.GoName, ` not implemented")`) + g.P("}") + } + if *requireUnimplemented { + g.P("func (Unimplemented", serverType, ") mustEmbedUnimplemented", serverType, "() {}") + } + g.P() +} + +func (serviceGenerateHelper) generateServerFunctions(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, serverType string, serviceDescVar string) { + // Server handler implementations. + handlerNames := make([]string, 0, len(service.Methods)) + for _, method := range service.Methods { + hname := genServerMethod(gen, file, g, method, func(hname string) string { + return hname + }) + handlerNames = append(handlerNames, hname) + } + genServiceDesc(file, g, serviceDescVar, serverType, service, handlerNames) +} + +func (serviceGenerateHelper) formatHandlerFuncName(service *protogen.Service, hname string) string { + return hname +} + +var helper serviceGenerateHelperInterface = serviceGenerateHelper{} + +// FileDescriptorProto.package field number +const fileDescriptorProtoPackageFieldNumber = 2 + +// FileDescriptorProto.syntax field number +const fileDescriptorProtoSyntaxFieldNumber = 12 + // generateFile generates a _grpc.pb.go file containing gRPC service definitions. func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.GeneratedFile { if len(file.Services) == 0 { @@ -41,6 +130,8 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated } filename := file.GeneratedFilenamePrefix + "_grpc.pb.go" g := gen.NewGeneratedFile(filename, file.GoImportPath) + // Attach all comments associated with the syntax field. + genLeadingComments(g, file.Desc.SourceLocations().ByPath(protoreflect.SourcePath{fileDescriptorProtoSyntaxFieldNumber})) g.P("// Code generated by protoc-gen-go-grpc. DO NOT EDIT.") g.P("// versions:") g.P("// - protoc-gen-go-grpc v", version) @@ -51,6 +142,8 @@ func generateFile(gen *protogen.Plugin, file *protogen.File) *protogen.Generated g.P("// source: ", file.Desc.Path()) } g.P() + // Attach all comments associated with the package field. + genLeadingComments(g, file.Desc.SourceLocations().ByPath(protoreflect.SourcePath{fileDescriptorProtoPackageFieldNumber})) g.P("package ", file.GoPackageName) g.P() generateFileContent(gen, file, g) @@ -86,13 +179,16 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen. } func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service) { + // Full methods constants. + helper.genFullMethods(g, service) + + // Client interface. clientName := service.GoName + "Client" g.P("// ", clientName, " is the client API for ", service.GoName, " service.") g.P("//") g.P("// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.") - // Client interface. if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { g.P("//") g.P(deprecationComment) @@ -111,17 +207,14 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P() // Client structure. - g.P("type ", unexport(clientName), " struct {") - g.P("cc ", grpcPackage.Ident("ClientConnInterface")) - g.P("}") - g.P() + helper.generateClientStruct(g, clientName) // NewClient factory. if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { g.P(deprecationComment) } g.P("func New", clientName, " (cc ", grpcPackage.Ident("ClientConnInterface"), ") ", clientName, " {") - g.P("return &", unexport(clientName), "{cc}") + helper.generateNewClientDefinitions(g, service, clientName) g.P("}") g.P() @@ -170,23 +263,7 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P() // Server Unimplemented struct for forward compatibility. - g.P("// Unimplemented", serverType, " ", mustOrShould, " be embedded to have forward compatible implementations.") - g.P("type Unimplemented", serverType, " struct {") - g.P("}") - g.P() - for _, method := range service.Methods { - nilArg := "" - if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { - nilArg = "nil," - } - g.P("func (Unimplemented", serverType, ") ", serverSignature(g, method), "{") - g.P("return ", nilArg, statusPackage.Ident("Errorf"), "(", codesPackage.Ident("Unimplemented"), `, "method `, method.GoName, ` not implemented")`) - g.P("}") - } - if *requireUnimplemented { - g.P("func (Unimplemented", serverType, ") mustEmbedUnimplemented", serverType, "() {}") - } - g.P() + helper.generateUnimplementedServerType(gen, file, g, service) // Unsafe Server interface to opt-out of forward compatibility. g.P("// Unsafe", serverType, " may be embedded to opt out of forward compatibility for this service.") @@ -206,51 +283,7 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P("}") g.P() - // Server handler implementations. - handlerNames := make([]string, 0, len(service.Methods)) - for _, method := range service.Methods { - hname := genServerMethod(gen, file, g, method) - handlerNames = append(handlerNames, hname) - } - - // Service descriptor. - g.P("// ", serviceDescVar, " is the ", grpcPackage.Ident("ServiceDesc"), " for ", service.GoName, " service.") - g.P("// It's only intended for direct use with ", grpcPackage.Ident("RegisterService"), ",") - g.P("// and not to be introspected or modified (even as a copy)") - g.P("var ", serviceDescVar, " = ", grpcPackage.Ident("ServiceDesc"), " {") - g.P("ServiceName: ", strconv.Quote(string(service.Desc.FullName())), ",") - g.P("HandlerType: (*", serverType, ")(nil),") - g.P("Methods: []", grpcPackage.Ident("MethodDesc"), "{") - for i, method := range service.Methods { - if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() { - continue - } - g.P("{") - g.P("MethodName: ", strconv.Quote(string(method.Desc.Name())), ",") - g.P("Handler: ", handlerNames[i], ",") - g.P("},") - } - g.P("},") - g.P("Streams: []", grpcPackage.Ident("StreamDesc"), "{") - for i, method := range service.Methods { - if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { - continue - } - g.P("{") - g.P("StreamName: ", strconv.Quote(string(method.Desc.Name())), ",") - g.P("Handler: ", handlerNames[i], ",") - if method.Desc.IsStreamingServer() { - g.P("ServerStreams: true,") - } - if method.Desc.IsStreamingClient() { - g.P("ClientStreams: true,") - } - g.P("},") - } - g.P("},") - g.P("Metadata: \"", file.Desc.Path(), "\",") - g.P("}") - g.P() + helper.generateServerFunctions(gen, file, g, service, serverType, serviceDescVar) } func clientSignature(g *protogen.GeneratedFile, method *protogen.Method) string { @@ -270,7 +303,7 @@ func clientSignature(g *protogen.GeneratedFile, method *protogen.Method) string func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, method *protogen.Method, index int) { service := method.Parent - sname := fmt.Sprintf("/%s/%s", service.Desc.FullName(), method.Desc.Name()) + fmSymbol := helper.formatFullMethodSymbol(service, method) if method.Desc.Options().(*descriptorpb.MethodOptions).GetDeprecated() { g.P(deprecationComment) @@ -278,7 +311,7 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene g.P("func (c *", unexport(service.GoName), "Client) ", clientSignature(g, method), "{") if !method.Desc.IsStreamingServer() && !method.Desc.IsStreamingClient() { g.P("out := new(", method.Output.GoIdent, ")") - g.P(`err := c.cc.Invoke(ctx, "`, sname, `", in, out, opts...)`) + g.P(`err := c.cc.Invoke(ctx, `, fmSymbol, `, in, out, opts...)`) g.P("if err != nil { return nil, err }") g.P("return out, nil") g.P("}") @@ -287,7 +320,7 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene } streamType := unexport(service.GoName) + method.GoName + "Client" serviceDescVar := service.GoName + "_ServiceDesc" - g.P("stream, err := c.cc.NewStream(ctx, &", serviceDescVar, ".Streams[", index, `], "`, sname, `", opts...)`) + g.P("stream, err := c.cc.NewStream(ctx, &", serviceDescVar, ".Streams[", index, `], `, fmSymbol, `, opts...)`) g.P("if err != nil { return nil, err }") g.P("x := &", streamType, "{stream}") if !method.Desc.IsStreamingClient() { @@ -363,18 +396,60 @@ func serverSignature(g *protogen.GeneratedFile, method *protogen.Method) string return method.GoName + "(" + strings.Join(reqArgs, ", ") + ") " + ret } -func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, method *protogen.Method) string { +func genServiceDesc(file *protogen.File, g *protogen.GeneratedFile, serviceDescVar string, serverType string, service *protogen.Service, handlerNames []string) { + // Service descriptor. + g.P("// ", serviceDescVar, " is the ", grpcPackage.Ident("ServiceDesc"), " for ", service.GoName, " service.") + g.P("// It's only intended for direct use with ", grpcPackage.Ident("RegisterService"), ",") + g.P("// and not to be introspected or modified (even as a copy)") + g.P("var ", serviceDescVar, " = ", grpcPackage.Ident("ServiceDesc"), " {") + g.P("ServiceName: ", strconv.Quote(string(service.Desc.FullName())), ",") + g.P("HandlerType: (*", serverType, ")(nil),") + g.P("Methods: []", grpcPackage.Ident("MethodDesc"), "{") + for i, method := range service.Methods { + if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() { + continue + } + g.P("{") + g.P("MethodName: ", strconv.Quote(string(method.Desc.Name())), ",") + g.P("Handler: ", handlerNames[i], ",") + g.P("},") + } + g.P("},") + g.P("Streams: []", grpcPackage.Ident("StreamDesc"), "{") + for i, method := range service.Methods { + if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { + continue + } + g.P("{") + g.P("StreamName: ", strconv.Quote(string(method.Desc.Name())), ",") + g.P("Handler: ", handlerNames[i], ",") + if method.Desc.IsStreamingServer() { + g.P("ServerStreams: true,") + } + if method.Desc.IsStreamingClient() { + g.P("ClientStreams: true,") + } + g.P("},") + } + g.P("},") + g.P("Metadata: \"", file.Desc.Path(), "\",") + g.P("}") + g.P() +} + +func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, method *protogen.Method, hnameFuncNameFormatter func(string) string) string { service := method.Parent hname := fmt.Sprintf("_%s_%s_Handler", service.GoName, method.GoName) if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() { - g.P("func ", hname, "(srv interface{}, ctx ", contextPackage.Ident("Context"), ", dec func(interface{}) error, interceptor ", grpcPackage.Ident("UnaryServerInterceptor"), ") (interface{}, error) {") + g.P("func ", hnameFuncNameFormatter(hname), "(srv interface{}, ctx ", contextPackage.Ident("Context"), ", dec func(interface{}) error, interceptor ", grpcPackage.Ident("UnaryServerInterceptor"), ") (interface{}, error) {") g.P("in := new(", method.Input.GoIdent, ")") g.P("if err := dec(in); err != nil { return nil, err }") g.P("if interceptor == nil { return srv.(", service.GoName, "Server).", method.GoName, "(ctx, in) }") g.P("info := &", grpcPackage.Ident("UnaryServerInfo"), "{") g.P("Server: srv,") - g.P("FullMethod: ", strconv.Quote(fmt.Sprintf("/%s/%s", service.Desc.FullName(), method.Desc.Name())), ",") + fmSymbol := helper.formatFullMethodSymbol(service, method) + g.P("FullMethod: ", fmSymbol, ",") g.P("}") g.P("handler := func(ctx ", contextPackage.Ident("Context"), ", req interface{}) (interface{}, error) {") g.P("return srv.(", service.GoName, "Server).", method.GoName, "(ctx, req.(*", method.Input.GoIdent, "))") @@ -385,7 +460,7 @@ func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene return hname } streamType := unexport(service.GoName) + method.GoName + "Server" - g.P("func ", hname, "(srv interface{}, stream ", grpcPackage.Ident("ServerStream"), ") error {") + g.P("func ", hnameFuncNameFormatter(hname), "(srv interface{}, stream ", grpcPackage.Ident("ServerStream"), ") error {") if !method.Desc.IsStreamingClient() { g.P("m := new(", method.Input.GoIdent, ")") g.P("if err := stream.RecvMsg(m); err != nil { return err }") @@ -444,6 +519,17 @@ func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene return hname } +func genLeadingComments(g *protogen.GeneratedFile, loc protoreflect.SourceLocation) { + for _, s := range loc.LeadingDetachedComments { + g.P(protogen.Comments(s)) + g.P() + } + if s := loc.LeadingComments; s != "" { + g.P(protogen.Comments(s)) + g.P() + } +} + const deprecationComment = "// Deprecated: Do not use." func unexport(s string) string { return strings.ToLower(s[:1]) + s[1:] } diff --git a/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/main.go b/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/main.go index 58cde2eb6..340eaf3ee 100644 --- a/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/main.go +++ b/vendor/google.golang.org/grpc/cmd/protoc-gen-go-grpc/main.go @@ -19,14 +19,17 @@ // protoc-gen-go-grpc is a plugin for the Google protocol buffer compiler to // generate Go code. Install it by building this program and making it // accessible within your PATH with the name: +// // protoc-gen-go-grpc // // The 'go-grpc' suffix becomes part of the argument for the protocol compiler, // such that it can be invoked as: +// // protoc --go-grpc_out=. path/to/file.proto // // This generates Go service definitions for the protocol buffer defined by // file.proto. With that input, the output will be written to: +// // path/to/file_grpc.pb.go package main @@ -38,7 +41,7 @@ import ( "google.golang.org/protobuf/types/pluginpb" ) -const version = "1.2.0" +const version = "1.3.0" var requireUnimplemented *bool diff --git a/vendor/modules.txt b/vendor/modules.txt index 2d3ffb752..1919f68d7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1108,8 +1108,8 @@ google.golang.org/grpc/serviceconfig google.golang.org/grpc/stats google.golang.org/grpc/status google.golang.org/grpc/tap -# google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0 -## explicit; go 1.9 +# google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 +## explicit; go 1.17 google.golang.org/grpc/cmd/protoc-gen-go-grpc # google.golang.org/protobuf v1.28.1 ## explicit; go 1.11 From 44efd39827e98366f2ffb20b64085a89797fb910 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 14 Mar 2023 14:48:31 +0100 Subject: [PATCH 2/2] build: prefer executables from the projects `bin/` dir for generation Signed-off-by: Niels de Vos --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0b413d176..57d49d0a3 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and .PHONY: generate-protobuf generate-protobuf: protoc-gen-go protoc-gen-go-grpc - PATH=$(PATH):$(shell pwd)/bin go generate ./internal/proto + PATH=$(shell pwd)/bin:$(PATH) go generate ./internal/proto .PHONY: fmt fmt: ## Run go fmt against code.