您好,登录后才能下订单哦!
本篇文章为大家展示了如何解决Golang获取google.golang.org/protobuf包报错的问题,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
今天在重新运行之前的老项目时,报了下面的错误:
# chris @ ChrisdeMacBook-Pro in ~/Go/src/hello [15:11:49] $ 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) import cycle not allowed package main imports github.com/astaxie/beego imports github.com/prometheus/client_golang/prometheus/promhttp imports github.com/prometheus/client_golang/prometheus imports github.com/golang/protobuf/proto imports google.golang.org/protobuf/proto imports google.golang.org/protobuf/proto ../google.golang.org/protobuf/proto/defaults.go:8:2: cannot find package "google.golang.org/protobuf/reflect/protoreflect" in any of: /usr/local/go/src/google.golang.org/protobuf/reflect/protoreflect (from $GOROOT) /Users/chris/Go/src/google.golang.org/protobuf/reflect/protoreflect (from $GOPATH) ../google.golang.org/protobuf/proto/extensions.go:15:2: cannot find package "google.golang.org/protobuf/reflect/protoregistry" in any of: /usr/local/go/src/google.golang.org/protobuf/reflect/protoregistry (from $GOROOT) /Users/chris/Go/src/google.golang.org/protobuf/reflect/protoregistry (from $GOPATH) ../google.golang.org/protobuf/proto/extensions.go:16:2: cannot find package "google.golang.org/protobuf/runtime/protoiface" in any of: /usr/local/go/src/google.golang.org/protobuf/runtime/protoiface (from $GOROOT) /Users/chris/Go/src/google.golang.org/protobuf/runtime/protoiface (from $GOPATH) ../google.golang.org/protobuf/proto/buffer.go:13:2: cannot find package "google.golang.org/protobuf/runtime/protoimpl" in any of: /usr/local/go/src/google.golang.org/protobuf/runtime/protoimpl (from $GOROOT) /Users/chris/Go/src/google.golang.org/protobuf/runtime/protoimpl (from $GOPATH) ../github.com/golang/protobuf/ptypes/any/any.pb.go:9:2: cannot find package "google.golang.org/protobuf/types/known/anypb" in any of: /usr/local/go/src/google.golang.org/protobuf/types/known/anypb (from $GOROOT) /Users/chris/Go/src/google.golang.org/protobuf/types/known/anypb (from $GOPATH) ../github.com/golang/protobuf/ptypes/duration/duration.pb.go:9:2: cannot find package "google.golang.org/protobuf/types/known/durationpb" in any of: /usr/local/go/src/google.golang.org/protobuf/types/known/durationpb (from $GOROOT) /Users/chris/Go/src/google.golang.org/protobuf/types/known/durationpb (from $GOPATH) ../github.com/golang/protobuf/ptypes/timestamp/timestamp.pb.go:9:2: cannot find package "google.golang.org/protobuf/types/known/timestamppb" in any of: /usr/local/go/src/google.golang.org/protobuf/types/known/timestamppb (from $GOROOT) /Users/chris/Go/src/google.golang.org/protobuf/types/known/timestamppb (from $GOPATH) # chris @ ChrisdeMacBook-Pro in ~/Go/src/hello [15:11:51] C:1 $
报错信息说的已经很明显了,就是调用包的时候找不到,所以我们需要对应下载。这里具体的操作方法是,从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
此时再次运行之前的启动命令就可以启动项目了~
另外,如果找不到对应google.golang.org包的话, 可以通过访问链接 google.golang.org/protobuf/encoding/prototext 根据提示找到 Index | Files 点击files 就可以找到github相应位置,在执行上面步骤就可以处理掉问题。
上述内容就是如何解决Golang获取google.golang.org/protobuf包报错的问题,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。