您好,登錄后才能下訂單哦!
本篇文章為大家展示了如何解決Golang獲取google.golang.org/protobuf包報(bào)錯(cuò)的問(wèn)題,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
今天在重新運(yùn)行之前的老項(xiàng)目時(shí),報(bào)了下面的錯(cuò)誤:
# 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 $
報(bào)錯(cuò)信息說(shuō)的已經(jīng)很明顯了,就是調(diào)用包的時(shí)候找不到,所以我們需要對(duì)應(yīng)下載。這里具體的操作方法是,從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
此時(shí)再次運(yùn)行之前的啟動(dòng)命令就可以啟動(dòng)項(xiàng)目了~
另外,如果找不到對(duì)應(yīng)google.golang.org包的話, 可以通過(guò)訪問(wèn)鏈接 google.golang.org/protobuf/encoding/prototext 根據(jù)提示找到 Index | Files 點(diǎn)擊files 就可以找到github相應(yīng)位置,在執(zhí)行上面步驟就可以處理掉問(wèn)題。
上述內(nèi)容就是如何解決Golang獲取google.golang.org/protobuf包報(bào)錯(cuò)的問(wèn)題,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。