您好,登錄后才能下訂單哦!
本篇文章為大家展示了如何解決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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。