I'm following the Protocol Buffer for Go tutorial but I have the following problem:
- I create the addressbook proto definition
syntax = "proto3"; package tutorial; message Person { string name = 1; ... }
- I successfully run the compiler and generate the go code
- I try to import the pb package but it fails
Here is exactly what happens: I specifying the --go_out
to be same as my proto definition: (protoc --go_out=. addressbook.proto
)
then in same folder, I create a test.go with these simple lines:
package main
import "tutorial"
but go build test.go
returns error:
test.go:3:8: cannot find package "tutorial" in any of:
/usr/local/go/src/tutorial (from $GOROOT)
/home/vagrant/go2/src/tutorial (from $GOPATH)
then I change test.go
to this:
package main
import "protobufs/tutorial"
and get this error:
test.go:3:8: cannot find package "protobufs/tutorial" in any of:
/usr/local/go/src/protobufs/tutorial (from $GOROOT)
/home/vagrant/go2/src/protobufs/tutorial (from $GOPATH)
but if I change the import to only:
package main
import "protobufs"
it finds that there's a "tutorial" package in that location:
test.go:3:8: found packages tutorial (addressbook.pb.go) and main (list_people.go) in /home/vagrant/go2/src/protobufs
What am I doing wrong ? How should the import look like in order to make this work ?
Thank you !
FYI: a snippet of my go env:
GOARCH="amd64"
GOBIN="/home/vagrant/go2/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/vagrant/go2"
GORACE=""
GOROOT="/usr/local/go"