


go grpc:無法匯入github.com/golang/protobuf/proto(沒有必要的模組提供套件「github.com/golang/protobuf/proto」)
php小編子墨在使用go grpc時遇到了一個錯誤,提示無法匯入"github.com/golang/protobuf/proto"模組。這個錯誤通常是因為缺少必需的模組導致的。在使用go grpc之前,我們需要確保已經正確安裝了protobuf函式庫,並在程式碼中正確匯入了相關的proto套件。接下來,我將為大家詳細介紹如何解決這個問題。
問題內容
當“protoc --proto_path=proto proto/*.proto --go_out=plugins”時,proto 檔案正在匯入“github.com/golang/protobuf/proto”而不是“google.golang.org/protobuf/proto” =grpc:pb"命令
導入檔案
#import ( fmt "fmt" proto "github.com/golang/protobuf/proto" math "math" ) ... > This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
我的原型檔案
#syntax="proto3"; message Processor{ string name=1; uint32 cores=2; uint32 min_ghz=3; uint32 max_ghz=4; }
~go/bin/protoc-gen-go-grpc 有版本
go: downloading google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 go: downloading google.golang.org/grpc v1.58.2 go: downloading google.golang.org/protobuf v1.28.1
我做了什麼
#初始安裝
$ go install google.golang.org/protobuf/cmd/[電子郵件受保護]
$ go install google.golang.org/grpc/cmd/[電子郵件受保護]
在安裝新軟體包之前輸入go clean -modcache,並使用註解@latest重新安裝最新版本
go 版本:Ubuntu 20.4 上的 go 版本 go1.21.1 linux/amd64
協定--版本 libprotoc 3.6.1
使用 apt 安裝了 protobuf-compiler 和 golang-goprotobuf
sudo apt install protobuf-compiler sudo apt install golang-goprotobuf -dev export PATH="$PATH:$(go env GOPATH)/bin"
我覺得問題就在這裡,但我不知道要修復什麼或如何閱讀此內容
go mod graph | grep github.com/golang/protobuf example-first github.com/golang/[email protected] github.com/golang/[email protected] github.com/google/[email protected] github.com/golang/[email protected] google.golang.org/[email protected] google.golang.org/[email protected] github.com/golang/[email protected] google.golang.org/[email protected] github.com/golang/[email protected] github.com/golang/[email protected] github.com/google/[email protected] github.com/golang/[email protected] google.golang.org/[email protected] go mod why github.com/golang/protobuf go: downloading github.com/golang/protobuf v1.5.3 go: downloading github.com/google/go-cmp v0.5.5 go: downloading golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 # github.com/golang/protobuf (main module does not need package github.com/golang/protobuf)
編輯:我想我最初使用go get -u github.com/golang/protobuf/proto 安裝了它,但我使用rm -rf $(go env GOPATH)/pkg/mod/github.com/golang 刪除了二進位檔案/protobuf/proto 並使用go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 安裝新版本並go install google.golang.org/grpc/cmd/protoc-gen-go- grpc@最新的。它仍然使用舊導入生成 go 檔案
Edit2:找不到 protoc-gen-go --version,但 protoc-gen-go-grpc --version 是 1.2.0。 protoc --版本是 libprotoc 3.6.1 whereis 協議-gen-go protoc-gen-go:/usr/bin/protoc-gen-go /home/hp/go/bin/protoc-gen-go /usr/share/man/man1/protoc-gen-go.1.gz p>
解決方法
如https://www.php.cn/link/a5481cd6d7517aa3fc6476dc7d9019ab<中提到的/a> 作者:@puellanivis
#Linux 環境中的$PATH
變數應以/home/{username}/go/bin
開頭,然後依序以/usr/bin
開頭。這是因為我們需要在 /usr/bin/protoc-gen-go
之前找到 google.golang.org/gprc/cmd/protoc-gen-go-grpc@latest
。
編輯 ~/.bashrc
或 ~/.bash_profile
檔案 ($vim ~/.bashrc
) 並手動匯出整個路徑環境。就我而言,我必須添加
export PATH=/home/hp/go/bin:/usr/local/go:/home/hp/go:usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
以上是go grpc:無法匯入github.com/golang/protobuf/proto(沒有必要的模組提供套件「github.com/golang/protobuf/proto」)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Golang在性能和可擴展性方面優於Python。 1)Golang的編譯型特性和高效並發模型使其在高並發場景下表現出色。 2)Python作為解釋型語言,執行速度較慢,但通過工具如Cython可優化性能。

Golang在並發性上優於C ,而C 在原始速度上優於Golang。 1)Golang通過goroutine和channel實現高效並發,適合處理大量並發任務。 2)C 通過編譯器優化和標準庫,提供接近硬件的高性能,適合需要極致優化的應用。

goimpactsdevelopmentpositationality throughspeed,效率和模擬性。 1)速度:gocompilesquicklyandrunseff,IdealforlargeProjects.2)效率:效率:ITScomprehenSevestAndardArdardArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdArdEcceSteral Depentencies,增強的Depleflovelmentimency.3)簡單性。

goisidealforbeginnersandsubableforforcloudnetworkservicesduetoitssimplicity,效率和concurrencyFeatures.1)installgromtheofficialwebsitealwebsiteandverifywith'.2)

Golang適合快速開發和並發場景,C 適用於需要極致性能和低級控制的場景。 1)Golang通過垃圾回收和並發機制提升性能,適合高並發Web服務開發。 2)C 通過手動內存管理和編譯器優化達到極致性能,適用於嵌入式系統開發。

Golang和Python各有优势:Golang适合高性能和并发编程,Python适用于数据科学和Web开发。Golang以其并发模型和高效性能著称,Python则以简洁语法和丰富库生态系统著称。

C 更適合需要直接控制硬件資源和高性能優化的場景,而Golang更適合需要快速開發和高並發處理的場景。 1.C 的優勢在於其接近硬件的特性和高度的優化能力,適合遊戲開發等高性能需求。 2.Golang的優勢在於其簡潔的語法和天然的並發支持,適合高並發服務開發。

Golang和C 在性能上的差異主要體現在內存管理、編譯優化和運行時效率等方面。 1)Golang的垃圾回收機制方便但可能影響性能,2)C 的手動內存管理和編譯器優化在遞歸計算中表現更為高效。
