Skip to content

Commit a4afd4d

Browse files
authored
deps: remove dependency of github.com/golang/protobuf from main module (#7122)
1 parent afaa301 commit a4afd4d

File tree

15 files changed

+492
-432
lines changed

15 files changed

+492
-432
lines changed

codegen.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

examples/gotutorial.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,10 @@ message Point {
8989

9090
## Generating client and server code
9191

92-
Next we need to generate the gRPC client and server interfaces from our `.proto` service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC Go plugin.
93-
94-
For simplicity, we've provided a [bash script](https://github.com/grpc/grpc-go/blob/master/codegen.sh) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this by yourself, make sure you've installed protoc and followed the gRPC-Go [installation instructions](https://github.com/grpc/grpc-go/blob/master/README.md) first):
95-
96-
```shell
97-
$ codegen.sh route_guide.proto
98-
```
99-
100-
which actually runs:
92+
Next we need to generate the gRPC client and server interfaces from our `.proto` service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC Go plugin (if you want to run this by yourself, make sure you've installed protoc and followed the gRPC-Go [installation instructions](https://github.com/grpc/grpc-go/blob/master/README.md) first) and run:
10193

10294
```shell
103-
$ protoc --go_out=plugins=grpc:. route_guide.proto
95+
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative "route_guide.proto"
10496
```
10597

10698
Running this command generates the following file in your current directory:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require (
77
github.com/cncf/xds/go v0.0.0-20240318125728-8a4994d93e50
88
github.com/envoyproxy/go-control-plane v0.12.0
99
github.com/golang/glog v1.2.0
10-
github.com/golang/protobuf v1.5.4
1110
github.com/google/go-cmp v0.6.0
1211
github.com/google/uuid v1.6.0
1312
golang.org/x/net v0.22.0
@@ -23,6 +22,7 @@ require (
2322
cloud.google.com/go/compute/metadata v0.2.3 // indirect
2423
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
2524
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
25+
github.com/golang/protobuf v1.5.4 // indirect
2626
golang.org/x/text v0.14.0 // indirect
2727
google.golang.org/appengine v1.6.8 // indirect
2828
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect

reflection/adapt.go

Lines changed: 4 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
package reflection
2020

2121
import (
22+
"google.golang.org/grpc/reflection/internal"
23+
2224
v1reflectiongrpc "google.golang.org/grpc/reflection/grpc_reflection_v1"
2325
v1reflectionpb "google.golang.org/grpc/reflection/grpc_reflection_v1"
2426
v1alphareflectiongrpc "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
25-
v1alphareflectionpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
2627
)
2728

2829
// asV1Alpha returns an implementation of the v1alpha version of the reflection
@@ -44,144 +45,13 @@ type v1AlphaServerStreamAdapter struct {
4445
}
4546

4647
func (s v1AlphaServerStreamAdapter) Send(response *v1reflectionpb.ServerReflectionResponse) error {
47-
return s.ServerReflection_ServerReflectionInfoServer.Send(v1ToV1AlphaResponse(response))
48+
return s.ServerReflection_ServerReflectionInfoServer.Send(internal.V1ToV1AlphaResponse(response))
4849
}
4950

5051
func (s v1AlphaServerStreamAdapter) Recv() (*v1reflectionpb.ServerReflectionRequest, error) {
5152
resp, err := s.ServerReflection_ServerReflectionInfoServer.Recv()
5253
if err != nil {
5354
return nil, err
5455
}
55-
return v1AlphaToV1Request(resp), nil
56-
}
57-
58-
func v1ToV1AlphaResponse(v1 *v1reflectionpb.ServerReflectionResponse) *v1alphareflectionpb.ServerReflectionResponse {
59-
var v1alpha v1alphareflectionpb.ServerReflectionResponse
60-
v1alpha.ValidHost = v1.ValidHost
61-
if v1.OriginalRequest != nil {
62-
v1alpha.OriginalRequest = v1ToV1AlphaRequest(v1.OriginalRequest)
63-
}
64-
switch mr := v1.MessageResponse.(type) {
65-
case *v1reflectionpb.ServerReflectionResponse_FileDescriptorResponse:
66-
if mr != nil {
67-
v1alpha.MessageResponse = &v1alphareflectionpb.ServerReflectionResponse_FileDescriptorResponse{
68-
FileDescriptorResponse: &v1alphareflectionpb.FileDescriptorResponse{
69-
FileDescriptorProto: mr.FileDescriptorResponse.GetFileDescriptorProto(),
70-
},
71-
}
72-
}
73-
case *v1reflectionpb.ServerReflectionResponse_AllExtensionNumbersResponse:
74-
if mr != nil {
75-
v1alpha.MessageResponse = &v1alphareflectionpb.ServerReflectionResponse_AllExtensionNumbersResponse{
76-
AllExtensionNumbersResponse: &v1alphareflectionpb.ExtensionNumberResponse{
77-
BaseTypeName: mr.AllExtensionNumbersResponse.GetBaseTypeName(),
78-
ExtensionNumber: mr.AllExtensionNumbersResponse.GetExtensionNumber(),
79-
},
80-
}
81-
}
82-
case *v1reflectionpb.ServerReflectionResponse_ListServicesResponse:
83-
if mr != nil {
84-
svcs := make([]*v1alphareflectionpb.ServiceResponse, len(mr.ListServicesResponse.GetService()))
85-
for i, svc := range mr.ListServicesResponse.GetService() {
86-
svcs[i] = &v1alphareflectionpb.ServiceResponse{
87-
Name: svc.GetName(),
88-
}
89-
}
90-
v1alpha.MessageResponse = &v1alphareflectionpb.ServerReflectionResponse_ListServicesResponse{
91-
ListServicesResponse: &v1alphareflectionpb.ListServiceResponse{
92-
Service: svcs,
93-
},
94-
}
95-
}
96-
case *v1reflectionpb.ServerReflectionResponse_ErrorResponse:
97-
if mr != nil {
98-
v1alpha.MessageResponse = &v1alphareflectionpb.ServerReflectionResponse_ErrorResponse{
99-
ErrorResponse: &v1alphareflectionpb.ErrorResponse{
100-
ErrorCode: mr.ErrorResponse.GetErrorCode(),
101-
ErrorMessage: mr.ErrorResponse.GetErrorMessage(),
102-
},
103-
}
104-
}
105-
default:
106-
// no value set
107-
}
108-
return &v1alpha
109-
}
110-
111-
func v1AlphaToV1Request(v1alpha *v1alphareflectionpb.ServerReflectionRequest) *v1reflectionpb.ServerReflectionRequest {
112-
var v1 v1reflectionpb.ServerReflectionRequest
113-
v1.Host = v1alpha.Host
114-
switch mr := v1alpha.MessageRequest.(type) {
115-
case *v1alphareflectionpb.ServerReflectionRequest_FileByFilename:
116-
v1.MessageRequest = &v1reflectionpb.ServerReflectionRequest_FileByFilename{
117-
FileByFilename: mr.FileByFilename,
118-
}
119-
case *v1alphareflectionpb.ServerReflectionRequest_FileContainingSymbol:
120-
v1.MessageRequest = &v1reflectionpb.ServerReflectionRequest_FileContainingSymbol{
121-
FileContainingSymbol: mr.FileContainingSymbol,
122-
}
123-
case *v1alphareflectionpb.ServerReflectionRequest_FileContainingExtension:
124-
if mr.FileContainingExtension != nil {
125-
v1.MessageRequest = &v1reflectionpb.ServerReflectionRequest_FileContainingExtension{
126-
FileContainingExtension: &v1reflectionpb.ExtensionRequest{
127-
ContainingType: mr.FileContainingExtension.GetContainingType(),
128-
ExtensionNumber: mr.FileContainingExtension.GetExtensionNumber(),
129-
},
130-
}
131-
}
132-
case *v1alphareflectionpb.ServerReflectionRequest_AllExtensionNumbersOfType:
133-
v1.MessageRequest = &v1reflectionpb.ServerReflectionRequest_AllExtensionNumbersOfType{
134-
AllExtensionNumbersOfType: mr.AllExtensionNumbersOfType,
135-
}
136-
case *v1alphareflectionpb.ServerReflectionRequest_ListServices:
137-
v1.MessageRequest = &v1reflectionpb.ServerReflectionRequest_ListServices{
138-
ListServices: mr.ListServices,
139-
}
140-
default:
141-
// no value set
142-
}
143-
return &v1
144-
}
145-
146-
func v1ToV1AlphaRequest(v1 *v1reflectionpb.ServerReflectionRequest) *v1alphareflectionpb.ServerReflectionRequest {
147-
var v1alpha v1alphareflectionpb.ServerReflectionRequest
148-
v1alpha.Host = v1.Host
149-
switch mr := v1.MessageRequest.(type) {
150-
case *v1reflectionpb.ServerReflectionRequest_FileByFilename:
151-
if mr != nil {
152-
v1alpha.MessageRequest = &v1alphareflectionpb.ServerReflectionRequest_FileByFilename{
153-
FileByFilename: mr.FileByFilename,
154-
}
155-
}
156-
case *v1reflectionpb.ServerReflectionRequest_FileContainingSymbol:
157-
if mr != nil {
158-
v1alpha.MessageRequest = &v1alphareflectionpb.ServerReflectionRequest_FileContainingSymbol{
159-
FileContainingSymbol: mr.FileContainingSymbol,
160-
}
161-
}
162-
case *v1reflectionpb.ServerReflectionRequest_FileContainingExtension:
163-
if mr != nil {
164-
v1alpha.MessageRequest = &v1alphareflectionpb.ServerReflectionRequest_FileContainingExtension{
165-
FileContainingExtension: &v1alphareflectionpb.ExtensionRequest{
166-
ContainingType: mr.FileContainingExtension.GetContainingType(),
167-
ExtensionNumber: mr.FileContainingExtension.GetExtensionNumber(),
168-
},
169-
}
170-
}
171-
case *v1reflectionpb.ServerReflectionRequest_AllExtensionNumbersOfType:
172-
if mr != nil {
173-
v1alpha.MessageRequest = &v1alphareflectionpb.ServerReflectionRequest_AllExtensionNumbersOfType{
174-
AllExtensionNumbersOfType: mr.AllExtensionNumbersOfType,
175-
}
176-
}
177-
case *v1reflectionpb.ServerReflectionRequest_ListServices:
178-
if mr != nil {
179-
v1alpha.MessageRequest = &v1alphareflectionpb.ServerReflectionRequest_ListServices{
180-
ListServices: mr.ListServices,
181-
}
182-
}
183-
default:
184-
// no value set
185-
}
186-
return &v1alpha
56+
return internal.V1AlphaToV1Request(resp), nil
18757
}

0 commit comments

Comments
 (0)