I'm working on migrating an older proto file that uses gRPC Gateway to protobuf apiv2. I'm able to generate the following files: api.pb.go
, api_grpc.pb.go
, and api.pg.gw.go
however when attempting to build the project I get the missing ProtoReflect method errors below.
I know the dependencies in the go mod file effect the generation of these files but this is the only configuration that has allowed me to generate the files.
I've tried following these references:
- https://grpc-ecosystem.github.io/grpc-gateway/docs/development/grpc-gateway_v2_migration_guide/
- https://go.dev/blog/protobuf-apiv2
But the information on integrating all these is limited.
The following is my relevant files
- Protoc Generation Script
#!/bin/sh
# Derive the path to the directory containing this script.
anchor="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
# Derive the path to the root protobuf directory.
root="$( echo "$anchor" | xargs dirname )"
export PATH="$PATH:${PATH}:${HOME}/go/bin"
echo $root
protoc -I "$root" \
--include_imports \
--descriptor_set_out="$root/api_descriptor.pb" \
api.proto
for proto in `find "$root" -name "*.proto"`; do
echo "Compiling $proto..."
protoc -I $root \
--go_out "$root" --go_opt paths=source_relative \
--go-grpc_out "$root" --go-grpc_opt paths=source_relative \
--grpc-gateway_out $root --grpc-gateway_opt paths=source_relative \
$proto
done
- Snippet of
api.proto
syntax = "proto3";
package protobuf;
option go_package = "./protobuf";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "google/api/annotations.proto";
//All Services Must Include a GetHealth Function on /
// -- Stream Manager Begins -- //
service StreamManagerService {
rpc CreateStream(CreateStreamRequest) returns (StreamResponse) {
option (google.api.http) = {
post: "/stream"
body: "*"
};
};
rpc GetAllStreams(google.protobuf.Empty) returns (AllStreamsResponse) {
option (google.api.http) = {
get: "/stream"
};
};
rpc GetStream(StreamRequest) returns (StreamResponse) {
option (google.api.http) = {
get: "/stream/{stream_id}"
};
};
rpc DeleteStream(StreamRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
delete: "/stream/{stream_id}"
};
};
rpc GetHealth (google.protobuf.Empty) returns (google.protobuf.Empty) {
option (google.api.http) = {
get: "/stream/healthz"
};
};
};
// -- Stream Begins -- //
service StreamService {
rpc CreateStream(CreateStreamRequest) returns (StreamResponse) {
option (google.api.http) = {
post: "/stream-new"
body: "*"
};
};
rpc GetAllStreams(google.protobuf.Empty) returns (AllStreamsResponse) {
option (google.api.http) = {
get: "/stream-new"
};
};
rpc GetStream(StreamRequest) returns (StreamResponse) {
option (google.api.http) = {
get: "/stream-new/{stream_id}"
};
};
rpc DeleteStream(StreamRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
delete: "/stream-new/{stream_id}"
};
};
rpc GetHealth (google.protobuf.Empty) returns (google.protobuf.Empty) {
option (google.api.http) = {
get: "/stream-new/healthz"
};
};
};
message CreateStreamRequest {
string source_url = 1;
string name = 2;
string desc = 3;
string source_type = 6;
int32 stream_id = 4; // optional - only use if recreating stream.
int32 frame_id = 5; // optional - only use if recreating stream.
}
message StreamRequest {
int32 stream_id = 2;
}
message StreamResponse {
int32 stream_id = 1;
string source_url = 2;
string stream_url = 3;
string name = 4;
string desc = 5;
string status = 6;
google.protobuf.Timestamp created = 7;
int32 res_w = 8;
int32 res_h = 9;
string source_type = 10;
}
message AllStreamsResponse {
repeated StreamResponse streams = 1;
}
// -- Stream Manager Ends -- //
go.mod
module github.com/inflowml/inflow-micro
go 1.19
require (
cloud.google.com/go/storage v1.6.0
firebase.google.com/go v3.13.0+incompatible
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3
github.com/lib/pq v1.10.7
github.com/streadway/amqp v1.0.0
gocv.io/x/gocv v0.31.0
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69
google.golang.org/api v0.22.0
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc
google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1
)
require (
cloud.google.com/go v0.54.0 // indirect
cloud.google.com/go/firestore v1.1.1 // indirect
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
go.opencensus.io v0.22.5 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.2.0 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/appengine v1.6.7 // indirect
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
)
- Error snippet
common/api/protobuf/api.pb.gw.go:109:9: cannot use msg (variable of type *GetRegionResponse) as type protoreflect.ProtoMessage in return statement:
*GetRegionResponse does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
common/api/protobuf/api.pb.gw.go:135:9: cannot use msg (variable of type *GetRegionResponse) as type protoreflect.ProtoMessage in return statement:
*GetRegionResponse does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
common/api/protobuf/api.pb.gw.go:221:9: cannot use msg (variable of type *QueryRegionResponse) as type protoreflect.ProtoMessage in return statement:
*QueryRegionResponse does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
common/api/protobuf/api.pb.gw.go:255:9: cannot use msg (variable of type *QueryRegionResponse) as type protoreflect.ProtoMessage in return statement:
*QueryRegionResponse does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
common/api/protobuf/api.pb.gw.go:289:9: cannot use msg (variable of type *GetDensityMatrixResponse) as type protoreflect.ProtoMessage in return statement:
*GetDensityMatrixResponse does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
common/api/protobuf/api.pb.gw.go:323:9: cannot use msg (variable of type *GetDensityMatrixResponse) as type protoreflect.ProtoMessage in return statement:
*GetDensityMatrixResponse does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
common/api/protobuf/api.pb.gw.go:323:9: too many errors