diff --git a/Dockerfile b/Dockerfile index 0617f6f9..17f7edc8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM golang:1.22-alpine3.20 as protoc-builder -ENV PROTOC_VERSION=27.2 +ENV PROTOC_VERSION=27.3 ARG TARGETARCH #hadolint ignore=DL3018 diff --git a/example/simple/client/main.go b/example/simple/client/main.go index ad4b474d..c89d92d0 100644 --- a/example/simple/client/main.go +++ b/example/simple/client/main.go @@ -201,4 +201,14 @@ func main() { log.Fatalf("error from grpc: %v", err) } log.Printf("Greeting: %s (return code %d)", r.GetMessage(), r.GetReturnCode()) + + r, err = c.SayHello(context.Background(), &pb.Request{Vint64: 10012}, grpc.UseCompressor(gzip.Name)) + if err != nil { + log.Fatalf("error from grpc: %v", err) + } + if r.GetMessage() != "Regexp matched" { + log.Fatalf("failed to get valid message: %v", r.GetMessage()) + } + + log.Printf("Greeting (gzip): %s (return code %d)", r.GetMessage(), r.GetReturnCode()) } diff --git a/example/simple/stub/uint64_int64.yml b/example/simple/stub/uint64_int64.yml index dac2d042..3b1c99bf 100644 --- a/example/simple/stub/uint64_int64.yml +++ b/example/simple/stub/uint64_int64.yml @@ -14,3 +14,11 @@ vint64: 72057594037927936 # {"high":18446744073709551615,"low":18446744073709551615} vuint64: 18446744073709551615 +- service: Gripmock + method: SayHello + input: + matches: + vint64: "^100[1-2]{2}\d{0,3}$" + output: + data: + message: "Regexp matched" diff --git a/go.mod b/go.mod index 5fa6face..b27bde67 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/bavix/features v1.0.0 github.com/bavix/gripmock-sdk-go v1.0.4 github.com/bavix/gripmock-ui v1.0.0-alpha7 - github.com/bavix/gripmock/protogen v0.0.0-20240729052235-50a4b281936f + github.com/bavix/gripmock/protogen v0.0.0-20240729213106-b0daec97f221 github.com/cristalhq/base64 v0.1.2 github.com/goccy/go-yaml v1.12.0 github.com/google/uuid v1.6.0 @@ -16,14 +16,14 @@ require ( github.com/gripmock/environment v1.0.4 github.com/gripmock/grpc-interceptors v1.0.2 github.com/gripmock/shutdown v1.0.0 - github.com/gripmock/stuber v1.1.0 + github.com/gripmock/stuber v1.1.1 github.com/jhump/protoreflect v1.16.0 github.com/oapi-codegen/runtime v1.1.1 github.com/pkg/errors v0.9.1 github.com/rs/zerolog v1.33.0 github.com/spf13/cobra v1.8.1 github.com/stretchr/testify v1.9.0 - google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f + google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 ) @@ -36,7 +36,7 @@ require ( github.com/fatih/color v1.17.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/golang/protobuf v1.5.4 // indirect - github.com/gripmock/deeply v1.2.0 // indirect + github.com/gripmock/deeply v1.2.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -49,7 +49,7 @@ require ( golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index b72d5b04..4554dd94 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/bavix/gripmock-sdk-go v1.0.4 h1:FDBlusqVFoy5Yo49khztYqfVt9+NSEf1mIl1n github.com/bavix/gripmock-sdk-go v1.0.4/go.mod h1:/1cmn8VuN6Pc7ttMejqXLYpvf1CJF08ezoEA9lJIZiU= github.com/bavix/gripmock-ui v1.0.0-alpha7 h1:0VDKdaUWgMBPURsLXtSt0FmCK4MKSxlSq+8u0ukfois= github.com/bavix/gripmock-ui v1.0.0-alpha7/go.mod h1:XEH4YYEKL+wEDtONntoWm6JxjbVWzl7XtDYztUTBfeA= -github.com/bavix/gripmock/protogen v0.0.0-20240729052235-50a4b281936f h1:pJyxFiCrI8GBbukq50oVN0eGEqJ5LdW8aRWXu0clB0w= -github.com/bavix/gripmock/protogen v0.0.0-20240729052235-50a4b281936f/go.mod h1:3CtbEfzqLiuFdhvtEKkSwOh9ZJDtnn085OYi/ekNcug= +github.com/bavix/gripmock/protogen v0.0.0-20240729213106-b0daec97f221 h1:vBOcfq3pg42VBppNT8oHgJvV8+2OExYnWHB/eaj26GM= +github.com/bavix/gripmock/protogen v0.0.0-20240729213106-b0daec97f221/go.mod h1:gwB6G6c1ZgBTAa+AlUqByark5JO7BGXjm87FsuA0csQ= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= github.com/bufbuild/protocompile v0.14.0 h1:z3DW4IvXE5G/uTOnSQn+qwQQxvhckkTWLS/0No/o7KU= github.com/bufbuild/protocompile v0.14.0/go.mod h1:N6J1NYzkspJo3ZwyL4Xjvli86XOj1xq4qAasUFxGups= @@ -52,16 +52,16 @@ github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyE github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= -github.com/gripmock/deeply v1.2.0 h1:gHiR5NoRB+RwhSNNF1Zl97BafaRr8/HOV5Bxa3YdVLM= -github.com/gripmock/deeply v1.2.0/go.mod h1:fqZtcO18v2rR9lLEJY7pgBHbTV0mrTFBYQiHOPAu9iQ= +github.com/gripmock/deeply v1.2.1 h1:cvVhOwXnFn8pEtRxl9dXCAerIMavEvMmHbGi9su3h0s= +github.com/gripmock/deeply v1.2.1/go.mod h1:fqZtcO18v2rR9lLEJY7pgBHbTV0mrTFBYQiHOPAu9iQ= github.com/gripmock/environment v1.0.4 h1:IqyFkwZ/s5ApJz+OD4yPfax6qlGftDaQ3zOqKNRDuMc= github.com/gripmock/environment v1.0.4/go.mod h1:nzBAHAw6/OYsng65X5q6HVmTmKtlvTHVdI/0OK1GGgQ= github.com/gripmock/grpc-interceptors v1.0.2 h1:wNmecrDlubuSXhJyJNfTM9ydPcY6w4Pz55HNoSrWRnc= github.com/gripmock/grpc-interceptors v1.0.2/go.mod h1:Bzh5pbb+sSC1vPmKTcEqg1jUUJFMAobQOuSKSXpMBMM= github.com/gripmock/shutdown v1.0.0 h1:ESDCCBeNHazgAstCpIskaORNWH3b+P03a2gznW+8IFY= github.com/gripmock/shutdown v1.0.0/go.mod h1:YwyI7uYgIPPdR9k8QNHwzDI2mQNpUSu+WT9mvqVoty4= -github.com/gripmock/stuber v1.1.0 h1:RpJ9cWP3shfyeC96phubwJlyFmXXtCxTyJRvd9bltqM= -github.com/gripmock/stuber v1.1.0/go.mod h1:3YhVm85Q30aOuYFKD0pr4Cz8Mzq66Yz8MQVx+YaZr2k= +github.com/gripmock/stuber v1.1.1 h1:6n7ml1yq1DGrDUXnGn9n7z7ExWxVENEl58Hm14Nwlbc= +github.com/gripmock/stuber v1.1.1/go.mod h1:BulrB4hoxCDH11OrdudBFHSrjAj+pPgr789lAWNwc2g= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jhump/protoreflect v1.16.0 h1:54fZg+49widqXYQ0b+usAFHbMkBGR4PpXrsHc8+TBDg= @@ -171,10 +171,10 @@ golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9 h1:LLhsEBxRTBLuKlQxFBYUOU8xyFgXv6cOTp2HASDlsDk= golang.org/x/xerrors v0.0.0-20240716161551-93cc26a95ae9/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= -google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f h1:b1Ln/PG8orm0SsBbHZWke8dDp2lrCD4jSmfglFpTZbk= -google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f/go.mod h1:AHT0dDg3SoMOgZGnZk29b5xTbPHMoEC8qthmBLJCpys= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f h1:RARaIm8pxYuxyNPbBQf5igT7XdOyCNtat1qAT2ZxjU4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf h1:GillM0Ef0pkZPIB+5iO6SDK+4T9pf6TpaYR6ICD5rVE= +google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:OFMYQFHJ4TM3JRlWDZhJbZfra2uqc3WLBZiaaqP4DtU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf h1:liao9UHurZLtiEwBgT9LMOnKYsHze6eA6w1KQCMVN2Q= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= diff --git a/go.work.sum b/go.work.sum index 5d2c497b..d8fcca6c 100644 --- a/go.work.sum +++ b/go.work.sum @@ -192,6 +192,10 @@ github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY= github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gripmock/deeply v1.2.0 h1:gHiR5NoRB+RwhSNNF1Zl97BafaRr8/HOV5Bxa3YdVLM= +github.com/gripmock/deeply v1.2.0/go.mod h1:fqZtcO18v2rR9lLEJY7pgBHbTV0mrTFBYQiHOPAu9iQ= +github.com/gripmock/stuber v1.1.0 h1:RpJ9cWP3shfyeC96phubwJlyFmXXtCxTyJRvd9bltqM= +github.com/gripmock/stuber v1.1.0/go.mod h1:3YhVm85Q30aOuYFKD0pr4Cz8Mzq66Yz8MQVx+YaZr2k= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= github.com/hydrogen18/memlistener v1.0.0/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= @@ -319,6 +323,7 @@ golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= diff --git a/internal/infra/muxmiddleware/logger.go b/internal/infra/muxmiddleware/logger.go index c1ef12af..8489f4bb 100644 --- a/internal/infra/muxmiddleware/logger.go +++ b/internal/infra/muxmiddleware/logger.go @@ -35,7 +35,8 @@ func RequestLogger(next http.Handler) http.Handler { Int("bytes", ww.bytesWritten). Int("code", ww.status) - if err := jsondecoder.UnmarshalSlice(bodyBytes, nil); err == nil { + var result []any + if err := jsondecoder.UnmarshalSlice(bodyBytes, &result); err == nil { event.RawJSON("input", bodyBytes) } diff --git a/protogen/example/ms/ms.pb.go b/protogen/example/ms/ms.pb.go index 0bc0a46e..13c54b21 100644 --- a/protogen/example/ms/ms.pb.go +++ b/protogen/example/ms/ms.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: ms.proto package ms diff --git a/protogen/example/ms/ms_grpc.pb.go b/protogen/example/ms/ms_grpc.pb.go index 7ddb5299..cb8e0ebe 100644 --- a/protogen/example/ms/ms_grpc.pb.go +++ b/protogen/example/ms/ms_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: ms.proto package ms @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( MicroService_SayHello_FullMethodName = "/ms.MicroService/SayHello" @@ -49,20 +49,24 @@ func (c *microServiceClient) SayHello(ctx context.Context, in *Request, opts ... // MicroServiceServer is the server API for MicroService service. // All implementations must embed UnimplementedMicroServiceServer -// for forward compatibility +// for forward compatibility. type MicroServiceServer interface { SayHello(context.Context, *Request) (*Reply, error) mustEmbedUnimplementedMicroServiceServer() } -// UnimplementedMicroServiceServer must be embedded to have forward compatible implementations. -type UnimplementedMicroServiceServer struct { -} +// UnimplementedMicroServiceServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedMicroServiceServer struct{} func (UnimplementedMicroServiceServer) SayHello(context.Context, *Request) (*Reply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } func (UnimplementedMicroServiceServer) mustEmbedUnimplementedMicroServiceServer() {} +func (UnimplementedMicroServiceServer) testEmbeddedByValue() {} // UnsafeMicroServiceServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to MicroServiceServer will @@ -72,6 +76,13 @@ type UnsafeMicroServiceServer interface { } func RegisterMicroServiceServer(s grpc.ServiceRegistrar, srv MicroServiceServer) { + // If the following call pancis, it indicates UnimplementedMicroServiceServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&MicroService_ServiceDesc, srv) } diff --git a/protogen/example/multi-files/file1.pb.go b/protogen/example/multi-files/file1.pb.go index 596e746c..24d367ae 100644 --- a/protogen/example/multi-files/file1.pb.go +++ b/protogen/example/multi-files/file1.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: file1.proto package multi_files diff --git a/protogen/example/multi-files/file1_grpc.pb.go b/protogen/example/multi-files/file1_grpc.pb.go index 5392f279..de87f110 100644 --- a/protogen/example/multi-files/file1_grpc.pb.go +++ b/protogen/example/multi-files/file1_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: file1.proto package multi_files @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Gripmock1_SayHello_FullMethodName = "/multifiles.Gripmock1/SayHello" @@ -52,7 +52,7 @@ func (c *gripmock1Client) SayHello(ctx context.Context, in *Request1, opts ...gr // Gripmock1Server is the server API for Gripmock1 service. // All implementations must embed UnimplementedGripmock1Server -// for forward compatibility +// for forward compatibility. // // The Gripmock service definition. type Gripmock1Server interface { @@ -61,14 +61,18 @@ type Gripmock1Server interface { mustEmbedUnimplementedGripmock1Server() } -// UnimplementedGripmock1Server must be embedded to have forward compatible implementations. -type UnimplementedGripmock1Server struct { -} +// UnimplementedGripmock1Server must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripmock1Server struct{} func (UnimplementedGripmock1Server) SayHello(context.Context, *Request1) (*Reply1, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } func (UnimplementedGripmock1Server) mustEmbedUnimplementedGripmock1Server() {} +func (UnimplementedGripmock1Server) testEmbeddedByValue() {} // UnsafeGripmock1Server may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to Gripmock1Server will @@ -78,6 +82,13 @@ type UnsafeGripmock1Server interface { } func RegisterGripmock1Server(s grpc.ServiceRegistrar, srv Gripmock1Server) { + // If the following call pancis, it indicates UnimplementedGripmock1Server was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Gripmock1_ServiceDesc, srv) } diff --git a/protogen/example/multi-files/file2.pb.go b/protogen/example/multi-files/file2.pb.go index e726ca53..5adaff2d 100644 --- a/protogen/example/multi-files/file2.pb.go +++ b/protogen/example/multi-files/file2.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: file2.proto package multi_files diff --git a/protogen/example/multi-files/file2_grpc.pb.go b/protogen/example/multi-files/file2_grpc.pb.go index 60f1feaa..8699a128 100644 --- a/protogen/example/multi-files/file2_grpc.pb.go +++ b/protogen/example/multi-files/file2_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: file2.proto package multi_files @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Gripmock2_SayHello_FullMethodName = "/multifiles.Gripmock2/SayHello" @@ -50,21 +50,25 @@ func (c *gripmock2Client) SayHello(ctx context.Context, in *Request2, opts ...gr // Gripmock2Server is the server API for Gripmock2 service. // All implementations must embed UnimplementedGripmock2Server -// for forward compatibility +// for forward compatibility. type Gripmock2Server interface { // simple unary method SayHello(context.Context, *Request2) (*Reply2, error) mustEmbedUnimplementedGripmock2Server() } -// UnimplementedGripmock2Server must be embedded to have forward compatible implementations. -type UnimplementedGripmock2Server struct { -} +// UnimplementedGripmock2Server must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripmock2Server struct{} func (UnimplementedGripmock2Server) SayHello(context.Context, *Request2) (*Reply2, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } func (UnimplementedGripmock2Server) mustEmbedUnimplementedGripmock2Server() {} +func (UnimplementedGripmock2Server) testEmbeddedByValue() {} // UnsafeGripmock2Server may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to Gripmock2Server will @@ -74,6 +78,13 @@ type UnsafeGripmock2Server interface { } func RegisterGripmock2Server(s grpc.ServiceRegistrar, srv Gripmock2Server) { + // If the following call pancis, it indicates UnimplementedGripmock2Server was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Gripmock2_ServiceDesc, srv) } diff --git a/protogen/example/multi-package/bar/bar.pb.go b/protogen/example/multi-package/bar/bar.pb.go index a86fcb9c..9cad8297 100644 --- a/protogen/example/multi-package/bar/bar.pb.go +++ b/protogen/example/multi-package/bar/bar.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: bar/bar.proto package bar diff --git a/protogen/example/multi-package/foo.pb.go b/protogen/example/multi-package/foo.pb.go index d884cc31..a922adbf 100644 --- a/protogen/example/multi-package/foo.pb.go +++ b/protogen/example/multi-package/foo.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: foo.proto // simulating neighboring .proto file diff --git a/protogen/example/multi-package/hello.pb.go b/protogen/example/multi-package/hello.pb.go index 14d56d90..d8ff3045 100644 --- a/protogen/example/multi-package/hello.pb.go +++ b/protogen/example/multi-package/hello.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: hello.proto package multi_package diff --git a/protogen/example/multi-package/hello_grpc.pb.go b/protogen/example/multi-package/hello_grpc.pb.go index 0c928832..c0f6e9d2 100644 --- a/protogen/example/multi-package/hello_grpc.pb.go +++ b/protogen/example/multi-package/hello_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: hello.proto package multi_package @@ -16,8 +16,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Gripmock_Greet_FullMethodName = "/multi_package.Gripmock/Greet" @@ -50,20 +50,24 @@ func (c *gripmockClient) Greet(ctx context.Context, in *bar.Bar, opts ...grpc.Ca // GripmockServer is the server API for Gripmock service. // All implementations must embed UnimplementedGripmockServer -// for forward compatibility +// for forward compatibility. type GripmockServer interface { Greet(context.Context, *bar.Bar) (*Response, error) mustEmbedUnimplementedGripmockServer() } -// UnimplementedGripmockServer must be embedded to have forward compatible implementations. -type UnimplementedGripmockServer struct { -} +// UnimplementedGripmockServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripmockServer struct{} func (UnimplementedGripmockServer) Greet(context.Context, *bar.Bar) (*Response, error) { return nil, status.Errorf(codes.Unimplemented, "method Greet not implemented") } func (UnimplementedGripmockServer) mustEmbedUnimplementedGripmockServer() {} +func (UnimplementedGripmockServer) testEmbeddedByValue() {} // UnsafeGripmockServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to GripmockServer will @@ -73,6 +77,13 @@ type UnsafeGripmockServer interface { } func RegisterGripmockServer(s grpc.ServiceRegistrar, srv GripmockServer) { + // If the following call pancis, it indicates UnimplementedGripmockServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Gripmock_ServiceDesc, srv) } diff --git a/protogen/example/one-of/oneof.pb.go b/protogen/example/one-of/oneof.pb.go index 04dbf358..17f8dd44 100644 --- a/protogen/example/one-of/oneof.pb.go +++ b/protogen/example/one-of/oneof.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: oneof.proto package one_of diff --git a/protogen/example/one-of/oneof_grpc.pb.go b/protogen/example/one-of/oneof_grpc.pb.go index 47b325fd..31a3c429 100644 --- a/protogen/example/one-of/oneof_grpc.pb.go +++ b/protogen/example/one-of/oneof_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: oneof.proto package one_of @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Gripmock_SayHello_FullMethodName = "/oneof.Gripmock/SayHello" @@ -52,7 +52,7 @@ func (c *gripmockClient) SayHello(ctx context.Context, in *Request, opts ...grpc // GripmockServer is the server API for Gripmock service. // All implementations must embed UnimplementedGripmockServer -// for forward compatibility +// for forward compatibility. // // The Gripmock service definition. type GripmockServer interface { @@ -61,14 +61,18 @@ type GripmockServer interface { mustEmbedUnimplementedGripmockServer() } -// UnimplementedGripmockServer must be embedded to have forward compatible implementations. -type UnimplementedGripmockServer struct { -} +// UnimplementedGripmockServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripmockServer struct{} func (UnimplementedGripmockServer) SayHello(context.Context, *Request) (*Reply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } func (UnimplementedGripmockServer) mustEmbedUnimplementedGripmockServer() {} +func (UnimplementedGripmockServer) testEmbeddedByValue() {} // UnsafeGripmockServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to GripmockServer will @@ -78,6 +82,13 @@ type UnsafeGripmockServer interface { } func RegisterGripmockServer(s grpc.ServiceRegistrar, srv GripmockServer) { + // If the following call pancis, it indicates UnimplementedGripmockServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Gripmock_ServiceDesc, srv) } diff --git a/protogen/example/simple/simple.pb.go b/protogen/example/simple/simple.pb.go index 4773486b..4ac39b8f 100644 --- a/protogen/example/simple/simple.pb.go +++ b/protogen/example/simple/simple.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: simple.proto package simple diff --git a/protogen/example/simple/simple_grpc.pb.go b/protogen/example/simple/simple_grpc.pb.go index d923884b..b95b5c67 100644 --- a/protogen/example/simple/simple_grpc.pb.go +++ b/protogen/example/simple/simple_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: simple.proto package simple @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Gripmock_SayHello_FullMethodName = "/simple.Gripmock/SayHello" @@ -52,7 +52,7 @@ func (c *gripmockClient) SayHello(ctx context.Context, in *Request, opts ...grpc // GripmockServer is the server API for Gripmock service. // All implementations must embed UnimplementedGripmockServer -// for forward compatibility +// for forward compatibility. // // The Gripmock service definition. type GripmockServer interface { @@ -61,14 +61,18 @@ type GripmockServer interface { mustEmbedUnimplementedGripmockServer() } -// UnimplementedGripmockServer must be embedded to have forward compatible implementations. -type UnimplementedGripmockServer struct { -} +// UnimplementedGripmockServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripmockServer struct{} func (UnimplementedGripmockServer) SayHello(context.Context, *Request) (*Reply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } func (UnimplementedGripmockServer) mustEmbedUnimplementedGripmockServer() {} +func (UnimplementedGripmockServer) testEmbeddedByValue() {} // UnsafeGripmockServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to GripmockServer will @@ -78,6 +82,13 @@ type UnsafeGripmockServer interface { } func RegisterGripmockServer(s grpc.ServiceRegistrar, srv GripmockServer) { + // If the following call pancis, it indicates UnimplementedGripmockServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Gripmock_ServiceDesc, srv) } diff --git a/protogen/example/stream/stream.pb.go b/protogen/example/stream/stream.pb.go index 733db9dd..4ef39075 100644 --- a/protogen/example/stream/stream.pb.go +++ b/protogen/example/stream/stream.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: stream.proto package stream diff --git a/protogen/example/stream/stream_grpc.pb.go b/protogen/example/stream/stream_grpc.pb.go index 4b262213..71a8f13d 100644 --- a/protogen/example/stream/stream_grpc.pb.go +++ b/protogen/example/stream/stream_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: stream.proto package stream @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Gripmock_ServerStream_FullMethodName = "/stream.Gripmock/serverStream" @@ -31,11 +31,11 @@ const ( // The Gripmock service definition. type GripmockClient interface { // server to client sreaming - ServerStream(ctx context.Context, in *Request, opts ...grpc.CallOption) (Gripmock_ServerStreamClient, error) + ServerStream(ctx context.Context, in *Request, opts ...grpc.CallOption) (grpc.ServerStreamingClient[Reply], error) // client to server streaming - ClientStream(ctx context.Context, opts ...grpc.CallOption) (Gripmock_ClientStreamClient, error) + ClientStream(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[Request, Reply], error) // bidirectional streaming - Bidirectional(ctx context.Context, opts ...grpc.CallOption) (Gripmock_BidirectionalClient, error) + Bidirectional(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Request, Reply], error) } type gripmockClient struct { @@ -46,13 +46,13 @@ func NewGripmockClient(cc grpc.ClientConnInterface) GripmockClient { return &gripmockClient{cc} } -func (c *gripmockClient) ServerStream(ctx context.Context, in *Request, opts ...grpc.CallOption) (Gripmock_ServerStreamClient, error) { +func (c *gripmockClient) ServerStream(ctx context.Context, in *Request, opts ...grpc.CallOption) (grpc.ServerStreamingClient[Reply], error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) stream, err := c.cc.NewStream(ctx, &Gripmock_ServiceDesc.Streams[0], Gripmock_ServerStream_FullMethodName, cOpts...) if err != nil { return nil, err } - x := &gripmockServerStreamClient{ClientStream: stream} + x := &grpc.GenericClientStream[Request, Reply]{ClientStream: stream} if err := x.ClientStream.SendMsg(in); err != nil { return nil, err } @@ -62,119 +62,68 @@ func (c *gripmockClient) ServerStream(ctx context.Context, in *Request, opts ... return x, nil } -type Gripmock_ServerStreamClient interface { - Recv() (*Reply, error) - grpc.ClientStream -} - -type gripmockServerStreamClient struct { - grpc.ClientStream -} - -func (x *gripmockServerStreamClient) Recv() (*Reply, error) { - m := new(Reply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Gripmock_ServerStreamClient = grpc.ServerStreamingClient[Reply] -func (c *gripmockClient) ClientStream(ctx context.Context, opts ...grpc.CallOption) (Gripmock_ClientStreamClient, error) { +func (c *gripmockClient) ClientStream(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[Request, Reply], error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) stream, err := c.cc.NewStream(ctx, &Gripmock_ServiceDesc.Streams[1], Gripmock_ClientStream_FullMethodName, cOpts...) if err != nil { return nil, err } - x := &gripmockClientStreamClient{ClientStream: stream} + x := &grpc.GenericClientStream[Request, Reply]{ClientStream: stream} return x, nil } -type Gripmock_ClientStreamClient interface { - Send(*Request) error - CloseAndRecv() (*Reply, error) - grpc.ClientStream -} - -type gripmockClientStreamClient struct { - grpc.ClientStream -} - -func (x *gripmockClientStreamClient) Send(m *Request) error { - return x.ClientStream.SendMsg(m) -} - -func (x *gripmockClientStreamClient) CloseAndRecv() (*Reply, error) { - if err := x.ClientStream.CloseSend(); err != nil { - return nil, err - } - m := new(Reply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Gripmock_ClientStreamClient = grpc.ClientStreamingClient[Request, Reply] -func (c *gripmockClient) Bidirectional(ctx context.Context, opts ...grpc.CallOption) (Gripmock_BidirectionalClient, error) { +func (c *gripmockClient) Bidirectional(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[Request, Reply], error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) stream, err := c.cc.NewStream(ctx, &Gripmock_ServiceDesc.Streams[2], Gripmock_Bidirectional_FullMethodName, cOpts...) if err != nil { return nil, err } - x := &gripmockBidirectionalClient{ClientStream: stream} + x := &grpc.GenericClientStream[Request, Reply]{ClientStream: stream} return x, nil } -type Gripmock_BidirectionalClient interface { - Send(*Request) error - Recv() (*Reply, error) - grpc.ClientStream -} - -type gripmockBidirectionalClient struct { - grpc.ClientStream -} - -func (x *gripmockBidirectionalClient) Send(m *Request) error { - return x.ClientStream.SendMsg(m) -} - -func (x *gripmockBidirectionalClient) Recv() (*Reply, error) { - m := new(Reply) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Gripmock_BidirectionalClient = grpc.BidiStreamingClient[Request, Reply] // GripmockServer is the server API for Gripmock service. // All implementations must embed UnimplementedGripmockServer -// for forward compatibility +// for forward compatibility. // // The Gripmock service definition. type GripmockServer interface { // server to client sreaming - ServerStream(*Request, Gripmock_ServerStreamServer) error + ServerStream(*Request, grpc.ServerStreamingServer[Reply]) error // client to server streaming - ClientStream(Gripmock_ClientStreamServer) error + ClientStream(grpc.ClientStreamingServer[Request, Reply]) error // bidirectional streaming - Bidirectional(Gripmock_BidirectionalServer) error + Bidirectional(grpc.BidiStreamingServer[Request, Reply]) error mustEmbedUnimplementedGripmockServer() } -// UnimplementedGripmockServer must be embedded to have forward compatible implementations. -type UnimplementedGripmockServer struct { -} +// UnimplementedGripmockServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripmockServer struct{} -func (UnimplementedGripmockServer) ServerStream(*Request, Gripmock_ServerStreamServer) error { +func (UnimplementedGripmockServer) ServerStream(*Request, grpc.ServerStreamingServer[Reply]) error { return status.Errorf(codes.Unimplemented, "method ServerStream not implemented") } -func (UnimplementedGripmockServer) ClientStream(Gripmock_ClientStreamServer) error { +func (UnimplementedGripmockServer) ClientStream(grpc.ClientStreamingServer[Request, Reply]) error { return status.Errorf(codes.Unimplemented, "method ClientStream not implemented") } -func (UnimplementedGripmockServer) Bidirectional(Gripmock_BidirectionalServer) error { +func (UnimplementedGripmockServer) Bidirectional(grpc.BidiStreamingServer[Request, Reply]) error { return status.Errorf(codes.Unimplemented, "method Bidirectional not implemented") } func (UnimplementedGripmockServer) mustEmbedUnimplementedGripmockServer() {} +func (UnimplementedGripmockServer) testEmbeddedByValue() {} // UnsafeGripmockServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to GripmockServer will @@ -184,6 +133,13 @@ type UnsafeGripmockServer interface { } func RegisterGripmockServer(s grpc.ServiceRegistrar, srv GripmockServer) { + // If the following call pancis, it indicates UnimplementedGripmockServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Gripmock_ServiceDesc, srv) } @@ -192,73 +148,25 @@ func _Gripmock_ServerStream_Handler(srv interface{}, stream grpc.ServerStream) e if err := stream.RecvMsg(m); err != nil { return err } - return srv.(GripmockServer).ServerStream(m, &gripmockServerStreamServer{ServerStream: stream}) -} - -type Gripmock_ServerStreamServer interface { - Send(*Reply) error - grpc.ServerStream -} - -type gripmockServerStreamServer struct { - grpc.ServerStream + return srv.(GripmockServer).ServerStream(m, &grpc.GenericServerStream[Request, Reply]{ServerStream: stream}) } -func (x *gripmockServerStreamServer) Send(m *Reply) error { - return x.ServerStream.SendMsg(m) -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Gripmock_ServerStreamServer = grpc.ServerStreamingServer[Reply] func _Gripmock_ClientStream_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(GripmockServer).ClientStream(&gripmockClientStreamServer{ServerStream: stream}) -} - -type Gripmock_ClientStreamServer interface { - SendAndClose(*Reply) error - Recv() (*Request, error) - grpc.ServerStream -} - -type gripmockClientStreamServer struct { - grpc.ServerStream -} - -func (x *gripmockClientStreamServer) SendAndClose(m *Reply) error { - return x.ServerStream.SendMsg(m) + return srv.(GripmockServer).ClientStream(&grpc.GenericServerStream[Request, Reply]{ServerStream: stream}) } -func (x *gripmockClientStreamServer) Recv() (*Request, error) { - m := new(Request) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Gripmock_ClientStreamServer = grpc.ClientStreamingServer[Request, Reply] func _Gripmock_Bidirectional_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(GripmockServer).Bidirectional(&gripmockBidirectionalServer{ServerStream: stream}) -} - -type Gripmock_BidirectionalServer interface { - Send(*Reply) error - Recv() (*Request, error) - grpc.ServerStream -} - -type gripmockBidirectionalServer struct { - grpc.ServerStream -} - -func (x *gripmockBidirectionalServer) Send(m *Reply) error { - return x.ServerStream.SendMsg(m) + return srv.(GripmockServer).Bidirectional(&grpc.GenericServerStream[Request, Reply]{ServerStream: stream}) } -func (x *gripmockBidirectionalServer) Recv() (*Request, error) { - m := new(Request) - if err := x.ServerStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Gripmock_BidirectionalServer = grpc.BidiStreamingServer[Request, Reply] // Gripmock_ServiceDesc is the grpc.ServiceDesc for Gripmock service. // It's only intended for direct use with grpc.RegisterService, diff --git a/protogen/example/strictmode/method.pb.go b/protogen/example/strictmode/method.pb.go index be1f8a64..d663926d 100644 --- a/protogen/example/strictmode/method.pb.go +++ b/protogen/example/strictmode/method.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: method.proto package strictmode diff --git a/protogen/example/strictmode/method_grpc.pb.go b/protogen/example/strictmode/method_grpc.pb.go index 3b470b13..c50ba650 100644 --- a/protogen/example/strictmode/method_grpc.pb.go +++ b/protogen/example/strictmode/method_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: method.proto package strictmode @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( GripMock_SayTitleHello_FullMethodName = "/strictmode.GripMock/SayTitleHello" @@ -61,16 +61,19 @@ func (c *gripMockClient) SayLowerHello(ctx context.Context, in *SayLowerHelloReq // GripMockServer is the server API for GripMock service. // All implementations must embed UnimplementedGripMockServer -// for forward compatibility +// for forward compatibility. type GripMockServer interface { SayTitleHello(context.Context, *SayTitleHelloRequest) (*SayTitleHelloReply, error) SayLowerHello(context.Context, *SayLowerHelloRequest) (*SayLowerHelloReply, error) mustEmbedUnimplementedGripMockServer() } -// UnimplementedGripMockServer must be embedded to have forward compatible implementations. -type UnimplementedGripMockServer struct { -} +// UnimplementedGripMockServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripMockServer struct{} func (UnimplementedGripMockServer) SayTitleHello(context.Context, *SayTitleHelloRequest) (*SayTitleHelloReply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayTitleHello not implemented") @@ -79,6 +82,7 @@ func (UnimplementedGripMockServer) SayLowerHello(context.Context, *SayLowerHello return nil, status.Errorf(codes.Unimplemented, "method SayLowerHello not implemented") } func (UnimplementedGripMockServer) mustEmbedUnimplementedGripMockServer() {} +func (UnimplementedGripMockServer) testEmbeddedByValue() {} // UnsafeGripMockServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to GripMockServer will @@ -88,6 +92,13 @@ type UnsafeGripMockServer interface { } func RegisterGripMockServer(s grpc.ServiceRegistrar, srv GripMockServer) { + // If the following call pancis, it indicates UnimplementedGripMockServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&GripMock_ServiceDesc, srv) } diff --git a/protogen/example/stub-subfolders/stub-subfolders.pb.go b/protogen/example/stub-subfolders/stub-subfolders.pb.go index 9f4638d6..cb2b9c97 100644 --- a/protogen/example/stub-subfolders/stub-subfolders.pb.go +++ b/protogen/example/stub-subfolders/stub-subfolders.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: stub-subfolders.proto package stub_subfolders diff --git a/protogen/example/stub-subfolders/stub-subfolders_grpc.pb.go b/protogen/example/stub-subfolders/stub-subfolders_grpc.pb.go index 9df769e8..1d02db53 100644 --- a/protogen/example/stub-subfolders/stub-subfolders_grpc.pb.go +++ b/protogen/example/stub-subfolders/stub-subfolders_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: stub-subfolders.proto package stub_subfolders @@ -15,8 +15,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Gripmock_SayHello_FullMethodName = "/stub_subfolders.Gripmock/SayHello" @@ -52,7 +52,7 @@ func (c *gripmockClient) SayHello(ctx context.Context, in *Request, opts ...grpc // GripmockServer is the server API for Gripmock service. // All implementations must embed UnimplementedGripmockServer -// for forward compatibility +// for forward compatibility. // // The Gripmock service definition. type GripmockServer interface { @@ -61,14 +61,18 @@ type GripmockServer interface { mustEmbedUnimplementedGripmockServer() } -// UnimplementedGripmockServer must be embedded to have forward compatible implementations. -type UnimplementedGripmockServer struct { -} +// UnimplementedGripmockServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripmockServer struct{} func (UnimplementedGripmockServer) SayHello(context.Context, *Request) (*Reply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } func (UnimplementedGripmockServer) mustEmbedUnimplementedGripmockServer() {} +func (UnimplementedGripmockServer) testEmbeddedByValue() {} // UnsafeGripmockServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to GripmockServer will @@ -78,6 +82,13 @@ type UnsafeGripmockServer interface { } func RegisterGripmockServer(s grpc.ServiceRegistrar, srv GripmockServer) { + // If the following call pancis, it indicates UnimplementedGripmockServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Gripmock_ServiceDesc, srv) } diff --git a/protogen/example/well_known_types/wkt.pb.go b/protogen/example/well_known_types/wkt.pb.go index f3ca833d..7daf962d 100644 --- a/protogen/example/well_known_types/wkt.pb.go +++ b/protogen/example/well_known_types/wkt.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc v5.27.3 // source: wkt.proto package well_known_types diff --git a/protogen/example/well_known_types/wkt_grpc.pb.go b/protogen/example/well_known_types/wkt_grpc.pb.go index afbf8d4b..5dfa7717 100644 --- a/protogen/example/well_known_types/wkt_grpc.pb.go +++ b/protogen/example/well_known_types/wkt_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.4.0 -// - protoc v5.27.2 +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.27.3 // source: wkt.proto package well_known_types @@ -17,8 +17,8 @@ import ( // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -// Requires gRPC-Go v1.62.0 or later. -const _ = grpc.SupportPackageIsVersion8 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 const ( Gripmock_ApiInfo_FullMethodName = "/well_known_types.Gripmock/ApiInfo" @@ -54,7 +54,7 @@ func (c *gripmockClient) ApiInfo(ctx context.Context, in *emptypb.Empty, opts .. // GripmockServer is the server API for Gripmock service. // All implementations must embed UnimplementedGripmockServer -// for forward compatibility +// for forward compatibility. type GripmockServer interface { // this shows us example on using WKT as dependency // api.proto in particular has go_package alias with semicolon @@ -63,14 +63,18 @@ type GripmockServer interface { mustEmbedUnimplementedGripmockServer() } -// UnimplementedGripmockServer must be embedded to have forward compatible implementations. -type UnimplementedGripmockServer struct { -} +// UnimplementedGripmockServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedGripmockServer struct{} func (UnimplementedGripmockServer) ApiInfo(context.Context, *emptypb.Empty) (*apipb.Api, error) { return nil, status.Errorf(codes.Unimplemented, "method ApiInfo not implemented") } func (UnimplementedGripmockServer) mustEmbedUnimplementedGripmockServer() {} +func (UnimplementedGripmockServer) testEmbeddedByValue() {} // UnsafeGripmockServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to GripmockServer will @@ -80,6 +84,13 @@ type UnsafeGripmockServer interface { } func RegisterGripmockServer(s grpc.ServiceRegistrar, srv GripmockServer) { + // If the following call pancis, it indicates UnimplementedGripmockServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } s.RegisterService(&Gripmock_ServiceDesc, srv) } diff --git a/protogen/go.mod b/protogen/go.mod index 35ca801c..f4ccbc6f 100644 --- a/protogen/go.mod +++ b/protogen/go.mod @@ -3,7 +3,7 @@ module github.com/bavix/gripmock/protogen go 1.22.2 require ( - google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f + google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf google.golang.org/grpc v1.65.0 google.golang.org/protobuf v1.34.2 ) @@ -12,5 +12,5 @@ require ( golang.org/x/net v0.27.0 // indirect golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect ) diff --git a/protogen/go.sum b/protogen/go.sum index dbe63095..b2da3e00 100644 --- a/protogen/go.sum +++ b/protogen/go.sum @@ -6,10 +6,10 @@ golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f h1:b1Ln/PG8orm0SsBbHZWke8dDp2lrCD4jSmfglFpTZbk= -google.golang.org/genproto/googleapis/api v0.0.0-20240725223205-93522f1f2a9f/go.mod h1:AHT0dDg3SoMOgZGnZk29b5xTbPHMoEC8qthmBLJCpys= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f h1:RARaIm8pxYuxyNPbBQf5igT7XdOyCNtat1qAT2ZxjU4= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240725223205-93522f1f2a9f/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf h1:GillM0Ef0pkZPIB+5iO6SDK+4T9pf6TpaYR6ICD5rVE= +google.golang.org/genproto/googleapis/api v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:OFMYQFHJ4TM3JRlWDZhJbZfra2uqc3WLBZiaaqP4DtU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf h1:liao9UHurZLtiEwBgT9LMOnKYsHze6eA6w1KQCMVN2Q= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=