Skip to content

Commit

Permalink
Resolve review comments: add some comments to clarify some confusion …
Browse files Browse the repository at this point in the history
…script or code

Signed-off-by: Benjamin Wang <[email protected]>
  • Loading branch information
ahrtr committed Sep 18, 2023
1 parent d06cdfa commit 8eba295
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scripts/genproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions server/embed/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 8eba295

Please sign in to comment.