From 8eba295bc5c5338b0495071bbdb8c445ce50a6df Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Mon, 18 Sep 2023 12:07:55 +0100 Subject: [PATCH] Resolve review comments: add some comments to clarify some confusion script or code Signed-off-by: Benjamin Wang --- scripts/genproto.sh | 22 ++++++++++++++++++++++ server/embed/serve.go | 1 + 2 files changed, 23 insertions(+) diff --git a/scripts/genproto.sh b/scripts/genproto.sh index 0de835a1343..0b6c20c292e 100755 --- a/scripts/genproto.sh +++ b/scripts/genproto.sh @@ -120,13 +120,35 @@ done # We only upgraded grpc-gateway from v1 to v2, but keep gogo/protobuf as it's for now. # So we have to convert v1 message to v2 message. Once we get rid of gogo/protobuf, and # start to depend on protobuf v2, then we can remove this patch. +# +# TODO(https://github.com/etcd-io/etcd/issues/14533): Remove the patch below after removal of gogo/protobuf for pb in api/etcdserverpb/rpc server/etcdserver/api/v3lock/v3lockpb/v3lock server/etcdserver/api/v3election/v3electionpb/v3election; do gwfile="$(dirname ${pb})/gw/$(basename ${pb}).pb.gw.go" + # Changes something like below, + # import ( + # + protov1 "github.com/golang/protobuf/proto" + # + run sed -i -E "s|import \(|import \(\n\tprotov1 \"github.com/golang/protobuf/proto\"\n|g" "${gwfile}" + + # Changes something like below, + # - return msg, metadata, err + # + return protov1.MessageV2(msg), metadata, err run sed -i -E "s|return msg, metadata, err|return protov1.MessageV2\(msg\), metadata, err|g" "${gwfile}" + + # Changes something like below, + # - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + # + if err := marshaler.NewDecoder(newReader()).Decode(protov1.MessageV2(&protoReq)); err != nil && err != io.EOF { run sed -i -E "s|Decode\(\&protoReq\)|Decode\(protov1\.MessageV2\(\&protoReq\)\)|g" "${gwfile}" + + # Changes something like below, + # - forward_Lease_LeaseKeepAlive_0(annotatedContext, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + # + forward_Lease_LeaseKeepAlive_0(annotatedContext, mux, outboundMarshaler, w, req, func() (proto.Message, error) { + # + m1, err := resp.Recv() + # + return protov1.MessageV2(m1), err + # + }, mux.GetForwardResponseOptions()...) run sed -i -E "s|return resp.Recv\(\)|\n\t\t\tm1, err := resp.Recv\(\)\n\t\t\treturn protov1.MessageV2\(m1\), err\n\t\t|g" "${gwfile}" + run go fmt "${gwfile}" done diff --git a/server/embed/serve.go b/server/embed/serve.go index 533254e8814..8825ab47ae4 100644 --- a/server/embed/serve.go +++ b/server/embed/serve.go @@ -303,6 +303,7 @@ func (sctx *serveCtx) registerGateway(dial func(ctx context.Context) (*grpc.Clie return nil, err } + // Refer to https://grpc-ecosystem.github.io/grpc-gateway/docs/mapping/customizing_your_gateway/ gwmux := gw.NewServeMux( gw.WithMarshalerOption(gw.MIMEWildcard, &gw.HTTPBodyMarshaler{