Open theoneLee opened 4 years ago
And I had already run those install script.
go get github.com/gogo/protobuf/protoc-gen-gofast
go get github.com/gogo/protobuf/proto
go get github.com/gogo/protobuf/jsonpb
go get github.com/gogo/protobuf/protoc-gen-gogo
go get github.com/gogo/protobuf/gogoproto
And my $GOPATH/bin had some exec programs.
edzdeMacBook-Pro:bin edz$ pwd
/Users/edz/go/bin
edzdeMacBook-Pro:bin edz$ ls
fillstruct gocode-gomod gopkgs gotests micro protoc-gen-gogo
go-outline godef gopls guru mockgen protoc-gen-micro
go-symbols goimports gorename hello_world protoc-gen-go xgen
gocode golint goreturns impl protoc-gen-gofast
But my $GOPATH/src doesn't have gogo dir. Is it the error reason?
edzdeMacBook-Pro:github.com edz$ go env
GO111MODULE="on"
GOPROXY="https://goproxy.cn,https://goproxy.io,direct"
i also meet this problem , how to solve it ?
hey @theoneLee, try to replace protoc -I=. ...
to protoc -I=. -I$(GOPATH)/src ...
in the makefile
Could you be able to resolve it?
I occur the same problem because I turn on GO111MODULE
. I solved this problem after executing those commands:
export GO111MODULE="off"
go get github.com/gogo/protobuf
Then make
could success:
smallyu@bogon example % make
(protoc -I=. -I=/Users/smallyu/go/src/github.com/gogo/protobuf/protobuf -I=/Users/smallyu/go/src --gogo_out=. example.proto)
smallyu@bogon example %
And when I want to generator another .proto
file, I use the command (after turn off GO111MODULE
and already get github.com/gogo/protobuf
):
protoc -I=. -I=$GOPATH/src/github.com/gogo/protobuf/protobuf -I=$GOPATH/src --gogo_out=. another.proto
I occur the same problem because I turn on
GO111MODULE
. I solved this problem after executing those commands:export GO111MODULE="off" go get github.com/gogo/protobuf
Then
make
could success:smallyu@bogon example % make (protoc -I=. -I=/Users/smallyu/go/src/github.com/gogo/protobuf/protobuf -I=/Users/smallyu/go/src --gogo_out=. example.proto) smallyu@bogon example %
And when I want to generator another
.proto
file, I use the command (after turn offGO111MODULE
and already getgithub.com/gogo/protobuf
):protoc -I=. -I=$GOPATH/src/github.com/gogo/protobuf/protobuf -I=$GOPATH/src --gogo_out=. another.proto
Agree with you. After turn off GO111MODULE, the problem is solved. My example is like:
proto file:
syntax = "proto3";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "google/protobuf/duration.proto";
Command line:
$ protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/gogo/protobuf/protobuf --gogo_opt=paths=source_relative --gogo_opt=Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types --gogo_out=. config.proto
I resolved this by specifying the proto_path
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
path/to/your/target/protofile --proto_path=$GOPATH/src/ --proto_path=.
--proto_path should be specified to the directory in which to search for imports
-> % protoc --help
Usage: protoc [OPTION] PROTO_FILES
Parse PROTO_FILES and generate output based on the options given:
-IPATH, --proto_path=PATH Specify the directory in which to search for
imports. May be specified multiple times;
directories will be searched in order. If not
given, the current working directory is used.
If not found in any of the these directories,
the --descriptor_set_in descriptors will be
checked for required proto file.
i can't
I run the demo and got an error.
https://github.com/gogo/protobuf/blob/master/test/example/example.proto