I have installed a protocol buffer like the tutorial on https://github.com/google/protobuf/blob/master/src/README.md
after that I want to build protobuf and install go library with command as follows:
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
I have file Makefile
on my root like this :
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
but I want to generate app and protobuf in my root of application with the command make
to build my app and the result like this:
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
after seeing the problem like this I check each of its directory, and it turns out there is all.
You'll need to wrap your $GOPATH like this
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:.
\\
added to make it easier to read here. The key is $(GOPATH)
vs $GOPATH
Here is a demo:
get:
echo $(GOPATH)
echo $GOPATH
and the output
echo /Users/sberry/Development/golang
/Users/sberry/Development/golang
echo OPATH
OPATH
In an editor that knows Makefile syntax you can see the difference
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.