Skip to content

Commit

Permalink
remove all usage of v1 grpc-gateway
Browse files Browse the repository at this point in the history
1. Manually updated go source file to remove the usage of v1 grpc-gateway;
2. Execute ./scripts/fix.sh

Signed-off-by: Benjamin Wang <[email protected]>
Signed-off-by: Wei Fu <[email protected]>
  • Loading branch information
ahrtr committed Sep 14, 2023
1 parent b4f10f1 commit 9ed20c4
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 922 deletions.
18 changes: 0 additions & 18 deletions bill-of-materials.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,6 @@
}
]
},
{
"project": "github.com/grpc-ecosystem/grpc-gateway",
"licenses": [
{
"type": "BSD 3-clause \"New\" or \"Revised\" License",
"confidence": 0.979253112033195
}
]
},
{
"project": "github.com/grpc-ecosystem/grpc-gateway/v2",
"licenses": [
Expand Down Expand Up @@ -701,15 +692,6 @@
}
]
},
{
"project": "google.golang.org/genproto/protobuf/field_mask",
"licenses": [
{
"type": "Apache License 2.0",
"confidence": 1
}
]
},
{
"project": "google.golang.org/grpc",
"licenses": [
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jonboulle/clockwork v0.4.0 // indirect
Expand Down
305 changes: 0 additions & 305 deletions go.sum

This file was deleted.

20 changes: 18 additions & 2 deletions server/embed/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ import (
v3lockgw "go.etcd.io/etcd/server/v3/etcdserver/api/v3lock/v3lockpb/gw"
"go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc"

gw "github.com/grpc-ecosystem/grpc-gateway/runtime"
gw "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/soheilhy/cmux"
"github.com/tmc/grpc-websocket-proxy/wsproxy"
"go.uber.org/zap"
"golang.org/x/net/http2"
"golang.org/x/net/trace"
"google.golang.org/grpc"
"google.golang.org/protobuf/encoding/protojson"
)

type serveCtx struct {
Expand Down Expand Up @@ -301,7 +302,22 @@ func (sctx *serveCtx) registerGateway(dial func(ctx context.Context) (*grpc.Clie
if err != nil {
return nil, err
}
gwmux := gw.NewServeMux()

gwmux := gw.NewServeMux(
gw.WithMarshalerOption(gw.MIMEWildcard,
&gw.HTTPBodyMarshaler{
Marshaler: &gw.JSONPb{
MarshalOptions: protojson.MarshalOptions{
UseProtoNames: true,
EmitUnpopulated: false,
},
UnmarshalOptions: protojson.UnmarshalOptions{
DiscardUnknown: true,
},
},
},
),
)

handlers := []registerHandlerFunc{
etcdservergw.RegisterKVHandler,
Expand Down
1 change: 0 additions & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/google/btree v1.1.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1
github.com/jonboulle/clockwork v0.4.0
github.com/prometheus/client_golang v1.16.0
Expand Down
279 changes: 0 additions & 279 deletions server/go.sum

This file was deleted.

13 changes: 10 additions & 3 deletions tests/e2e/v3_curl_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
"encoding/json"
"testing"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
protov1 "github.com/golang/protobuf/proto"
gw "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"

pb "go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/pkg/v3/expect"
Expand Down Expand Up @@ -151,8 +153,13 @@ func testCurlV3KVTxn(cx ctlCtx) {
},
},
}
m := &runtime.JSONPb{}
jsonDat, jerr := m.Marshal(txn)
m := gw.JSONPb{
MarshalOptions: protojson.MarshalOptions{
UseProtoNames: true,
EmitUnpopulated: false,
},
}
jsonDat, jerr := m.Marshal(protov1.MessageV2(txn))
require.NoError(cx.t, jerr)

succeeded, responses := mustExecuteTxn(cx, string(jsonDat))
Expand Down
7 changes: 3 additions & 4 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ replace (
require (
github.com/anishathalye/porcupine v0.1.4
github.com/coreos/go-semver v0.3.1
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.5.9
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/common v0.43.0
github.com/soheilhy/cmux v0.1.5
Expand All @@ -44,6 +45,7 @@ require (
golang.org/x/sync v0.3.0
golang.org/x/time v0.3.0
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
)

require (
Expand All @@ -64,10 +66,8 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jonboulle/clockwork v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down Expand Up @@ -95,7 +95,6 @@ require (
google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 9ed20c4

Please sign in to comment.