我安装了一个协议缓冲区,就像https://github.com/google/protobuf/blob/master/src/README.md
上的教程一样之后我想构建protobuf并使用如下命令安装go library:
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go
make # generate app and protobuf
我的根目录中有Makefile
文件,如下所示:
get:
echo "Build Proto"
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis proto/item.proto --go_out=plugins=grpc:.
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis proto/item.proto --grpc-gateway_out=logtostderr=true:.
protoc -I/usr/local/include -I. -I$GOPATH/src -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis proto/item.proto --swagger_out=logtostderr=true:.
echo "Build APP"
CGO_ENABLED=0 GOOS=linux go build -o ./server/storeitemservice ./server/cmd/server/main.go
但是我希望使用命令make
在我的应用程序根目录中生成app和protobuf来构建我的应用程序,结果如下:
echo "Build Proto"
Build Proto
protoc -I/usr/local/include -I. -IOPATH/src -IOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis proto/item.proto --go_out=plugins=grpc:.
OPATH/src: warning: directory does not exist.
OPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis: warning: directory does not exist.
google/api/annotations.proto: File not found.
proto/item.proto: Import "google/api/annotations.proto" was not found or had errors.
Makefile:2: recipe for target 'get' failed
make: *** [get] Error 1
在看到这样的问题之后,我检查了它的每个目录,结果证明存在这一切。
答案 0 :(得分:1)
你需要像这样包装你的$ GOPATH
protoc -I/usr/local/include -I. -I$(GOPATH)/src \
-I$(GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
proto/item.proto --go_out=plugins=grpc:.
添加了 \
以便于在此处阅读。关键是$(GOPATH)
vs $GOPATH
这是一个演示:
get:
echo $(GOPATH)
echo $GOPATH
和输出
echo /Users/sberry/Development/golang
/Users/sberry/Development/golang
echo OPATH
OPATH
在知道Makefile语法的编辑器中,您可以看到差异