如何解决Golang获取google.golang.org/protobuf包报错的问题

$ go run main.go
…/github.com/golang/protobuf/proto/buffer.go:11:2: cannot find package “google.golang.org/protobuf/encoding/prototext” in any of:
/usr/local/go/src/google.golang.org/protobuf/encoding/prototext (from $GOROOT)
/Users/chris/Go/src/google.golang.org/protobuf/encoding/prototext (from $GOPATH)
…/github.com/golang/protobuf/proto/buffer.go:12:2: cannot find package “google.golang.org/protobuf/encoding/protowire” in any of:
/usr/local/go/src/google.golang.org/protobuf/encoding/protowire (from $GOROOT)
/Users/chris/Go/src/google.golang.org/protobuf/encoding/protowire (from $GOPATH)

报错信息说的已经很明显了,就是调用包的时候找不到,所以我们需要对应下载。这里具体的操作方法是,从https://github.com/protocolbuffers/protobuf-go/tree/master/ 下载包,放到%GOPATH%\google.golang.org\protobuf下就可以。

mkdir google.golang.org
cd google.golang.org
git clone https://github.com/protocolbuffers/protobuf-go.git
mv protobuf-go protobuf
此时再次运行之前的启动命令就可以启动项目了~

你可能感兴趣的:(常见问题,golang)