Skip to content

Commit ad1c1bb

Browse files
authored
refactor: upgrade protoc-gen-grpc-gateway to use the new Go code generator (#1668)
* refactor: upgrade protoc-gen-grpc-gateway to use the new Go code generator This change upgrades protoc-gen-grpc-gateway to use google.golang.org/protobuf/compiler/protogen which is the new package for writing protoc plugins generating Go code. It also fixes all places to use packages from google.golang.org/protobuf module instead of github.com/golang/protobuf. Signed-off-by: Adam Babik <[email protected]> * refactor: regenerate BUILD.bazel files Signed-off-by: Adam Babik <[email protected]>
1 parent 6c222a8 commit ad1c1bb

File tree

24 files changed

+143
-138
lines changed

24 files changed

+143
-138
lines changed

internal/codegenerator/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ go_library(
1010
],
1111
importpath = "github.com/grpc-ecosystem/grpc-gateway/v2/internal/codegenerator",
1212
deps = [
13-
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
1413
"@org_golang_google_protobuf//proto:go_default_library",
14+
"@org_golang_google_protobuf//types/pluginpb:go_default_library",
1515
],
1616
)
1717

@@ -21,8 +21,8 @@ go_test(
2121
embed = [":go_default_library"],
2222
deps = [
2323
"@com_github_google_go_cmp//cmp:go_default_library",
24-
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
2524
"@org_golang_google_protobuf//proto:go_default_library",
2625
"@org_golang_google_protobuf//testing/protocmp:go_default_library",
26+
"@org_golang_google_protobuf//types/pluginpb:go_default_library",
2727
],
2828
)

internal/codegenerator/parse_req.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"io"
66
"io/ioutil"
77

8-
pluginpb "github.com/golang/protobuf/protoc-gen-go/plugin"
98
"google.golang.org/protobuf/proto"
9+
"google.golang.org/protobuf/types/pluginpb"
1010
)
1111

1212
// ParseRequest parses a code generator request from a proto Message.

internal/codegenerator/parse_req_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"strings"
99
"testing"
1010

11-
pluginpb "github.com/golang/protobuf/protoc-gen-go/plugin"
1211
"github.com/google/go-cmp/cmp"
1312
"github.com/grpc-ecosystem/grpc-gateway/v2/internal/codegenerator"
1413
"google.golang.org/protobuf/proto"
1514
"google.golang.org/protobuf/testing/protocmp"
15+
"google.golang.org/protobuf/types/pluginpb"
1616
)
1717

1818
var parseReqTests = []struct {

internal/descriptor/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ go_library(
1818
"@com_github_ghodss_yaml//:go_default_library",
1919
"@com_github_golang_glog//:go_default_library",
2020
"@go_googleapis//google/api:annotations_go_proto",
21-
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
22-
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
2321
"@org_golang_google_protobuf//encoding/protojson:go_default_library",
2422
"@org_golang_google_protobuf//proto:go_default_library",
23+
"@org_golang_google_protobuf//types/descriptorpb:go_default_library",
24+
"@org_golang_google_protobuf//types/pluginpb:go_default_library",
2525
],
2626
)
2727

@@ -37,9 +37,9 @@ go_test(
3737
embed = [":go_default_library"],
3838
deps = [
3939
"//internal/httprule:go_default_library",
40-
"@io_bazel_rules_go//proto/wkt:compiler_plugin_go_proto",
41-
"@io_bazel_rules_go//proto/wkt:descriptor_go_proto",
4240
"@org_golang_google_protobuf//encoding/prototext:go_default_library",
4341
"@org_golang_google_protobuf//proto:go_default_library",
42+
"@org_golang_google_protobuf//types/descriptorpb:go_default_library",
43+
"@org_golang_google_protobuf//types/pluginpb:go_default_library",
4444
],
4545
)

internal/descriptor/registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"strings"
88

99
"github.com/golang/glog"
10-
descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
11-
pluginpb "github.com/golang/protobuf/protoc-gen-go/plugin"
1210
"google.golang.org/genproto/googleapis/api/annotations"
11+
"google.golang.org/protobuf/types/descriptorpb"
12+
"google.golang.org/protobuf/types/pluginpb"
1313
)
1414

1515
// Registry is a registry of information extracted from pluginpb.CodeGeneratorRequest.

internal/descriptor/registry_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package descriptor
33
import (
44
"testing"
55

6-
descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
7-
pluginpb "github.com/golang/protobuf/protoc-gen-go/plugin"
86
"google.golang.org/protobuf/encoding/prototext"
7+
"google.golang.org/protobuf/types/descriptorpb"
8+
"google.golang.org/protobuf/types/pluginpb"
99
)
1010

1111
func loadFile(t *testing.T, reg *Registry, src string) *descriptorpb.FileDescriptorProto {

internal/descriptor/services.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"strings"
66

77
"github.com/golang/glog"
8-
descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
98
"github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule"
109
options "google.golang.org/genproto/googleapis/api/annotations"
1110
"google.golang.org/protobuf/proto"
11+
"google.golang.org/protobuf/types/descriptorpb"
1212
)
1313

1414
// loadServices registers services and their methods from "targetFile" to "r".
@@ -37,7 +37,7 @@ func (r *Registry) loadServices(file *File) error {
3737
}
3838
if len(optsList) == 0 {
3939
logFn := glog.V(1).Infof
40-
if r.warnOnUnboundMethods {
40+
if r.warnOnUnboundMethods {
4141
logFn = glog.Warningf
4242
}
4343
logFn("No HttpRule found for method: %s.%s", svc.GetName(), md.GetName())

internal/descriptor/services_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"reflect"
55
"testing"
66

7-
descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
87
"github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule"
98
"google.golang.org/protobuf/encoding/prototext"
109
"google.golang.org/protobuf/proto"
10+
"google.golang.org/protobuf/types/descriptorpb"
1111
)
1212

1313
func compilePath(t *testing.T, path string) httprule.Template {

internal/descriptor/types.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"fmt"
55
"strings"
66

7-
descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
87
"github.com/grpc-ecosystem/grpc-gateway/v2/internal/casing"
98
"github.com/grpc-ecosystem/grpc-gateway/v2/internal/httprule"
9+
"google.golang.org/protobuf/types/descriptorpb"
10+
"google.golang.org/protobuf/types/pluginpb"
1011
)
1112

1213
// IsWellKnownType returns true if the provided fully qualified type name is considered 'well-known'.
@@ -41,7 +42,7 @@ func (p GoPackage) String() string {
4142
// File wraps descriptorpb.FileDescriptorProto for richer features.
4243
type File struct {
4344
*descriptorpb.FileDescriptorProto
44-
// GoPkg is the go package of the go file generated from this file..
45+
// GoPkg is the go package of the go file generated from this file.
4546
GoPkg GoPackage
4647
// Messages is the list of messages defined in this file.
4748
Messages []*Message
@@ -65,6 +66,14 @@ func (f *File) proto2() bool {
6566
return f.Syntax == nil || f.GetSyntax() == "proto2"
6667
}
6768

69+
// ResponseFile wraps pluginpb.CodeGeneratorResponse_File.
70+
type ResponseFile struct {
71+
*pluginpb.CodeGeneratorResponse_File
72+
73+
// GoPkg is the Go package of the generated file.
74+
GoPkg GoPackage
75+
}
76+
6877
// Message describes a protocol buffer message types
6978
type Message struct {
7079
// File is the file where the message is defined

internal/descriptor/types_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package descriptor
33
import (
44
"testing"
55

6-
descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
76
"google.golang.org/protobuf/encoding/prototext"
7+
"google.golang.org/protobuf/types/descriptorpb"
88
)
99

1010
func TestGoPackageStandard(t *testing.T) {

0 commit comments

Comments
 (0)