IDEA使用go mod加載依賴


GO MOD

go mod是go語言的依賴管理工具

目錄

go mod 指令介紹

go mod command

命令 說明
download download modules to local cache(下載依賴包)
edit edit go.mod from tools or scripts(編輯go.mod)
graphprint module requirement graph (打印模塊依賴圖)
verify initialize new module in current directory(在當前目錄初始化mod)
tidy add missing and remove unused modules(拉取缺少的模塊,移除不用的模塊)
vendor make vendored copy of dependencies(將依賴復制到vendor下)
verify verify dependencies have expected content (驗證依賴是否正確)
why explain why packages or modules are needed(解釋為什么需要依賴)

IDEA加載項目

  • 配置全局GOPATH --- 類似本地go依賴倉庫,配置后可使用本地倉庫的依賴
  • 缺少的依賴使用go mod tidy將需要的依賴下載到GOPATH下
  • go.mod文件里面 點擊刷新,idea就會重新加載GOPATH下的依賴
  • 有些依賴是git私有倉庫,可能需要配置倉庫訪問方式
    • [舉例] [配置git將請求從ssh轉化為http:] git config --global url."ssh://git@gitlab.com:33333".insteadOf "http://gitlab.com"
    • 如果定義了GOPROXY環境變量,額外定義 GOPRIVATE=gitlab.com
      • go env -w GOPRIVATE=gitlab.com


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM