0
votes

I'm trying to use https://github.com/grpc-ecosystem/grpc-gateway but when I try to run

protoc -I/usr/local/include -I. -I${GOPATH}/src -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc,paths=source_relative:./ example/example.proto

ERROR src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis: warning: directory does not exist.

To solve this I bring the necessary files manually,but I feel this is unnesesary there is a way to make this automatic, I run before go get -u github.com/grpc-ecosystem/grpc-gateway/

but is still no way

2
Are you sure the ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis exists? can you try to open it? with cd ?Alexsandro Souza
Thats the problem It doesn't existdelfosk9

2 Answers

1
votes

The protos you are trying to download is from this module

env GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
0
votes

Have a look at this (extract from a Dockerfile):

ARG VERS="3.13.0"
ARG ARCH="linux-x86_64"
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v${VERS}/protoc-${VERS}-${ARCH}.zip --output-document=./protoc-${VERS}-${ARCH}.zip && \
    apt update && apt install -y unzip && \
    unzip -o protoc-${VERS}-${ARCH}.zip -d protoc-${VERS}-${ARCH} && \
    mv protoc-${VERS}-${ARCH}/bin/* /usr/local/bin && \
    mv protoc-${VERS}-${ARCH}/include/* /usr/local/include && \
    go get -u github.com/golang/protobuf/protoc-gen-go && \
    go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

ARG REPO="..."
ARG MODULE="github.com/${REPO}"

# Generates the Golang protobuf files
# NB Uses `go list` to determine the correct Modules directory for the package (!) containing Google APIs protos
RUN protoc \
    --proto_path=. \
    --proto_path=$(go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis \
    --go_out=plugins=grpc,module=${MODULE}:. \
    ./protos/*.proto

I use this snippet frequently when building gRPC-based solutions that use gRPC gateway.

The first RUN gets protoc, protoc-gen-go and -protoc-gen-grpc-gateway.

The second RUN uses go list to identify the installed grpc-gateway module and points protoc at it.