亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么自 Go 1.17 以來,go.mod 中有兩個“需要”塊?

為什么自 Go 1.17 以來,go.mod 中有兩個“需要”塊?

Go
慕桂英4014372 2022-10-04 18:51:24
我創建了一個小型 go 應用程序。幾天前,我已經從go 1.15升級到1.17,我還用升級了軟件包。更改后,我的go.mod文件中有2個需要塊。這是為什么呢?這是什么意思?還好還是有什么東西壞了?go get -u應用程序仍可正確生成。文件:module github.com/jozo/simple-pomodorogo 1.17require (    fyne.io/fyne/v2 v2.1.0    github.com/dsnet/golib/memfile v1.0.0    github.com/faiface/beep v1.1.0    github.com/fsnotify/fsnotify v1.5.1 // indirect    github.com/go-gl/gl v0.0.0-20210905235341-f7a045908259 // indirect    github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210727001814-0db043d8d5be // indirect    github.com/godbus/dbus/v5 v5.0.5 // indirect    github.com/hajimehoshi/oto v1.0.1 // indirect    github.com/srwiley/oksvg v0.0.0-20210519022825-9fc0c575d5fe // indirect    github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect    github.com/yuin/goldmark v1.4.1 // indirect    golang.org/x/exp v0.0.0-20210916165020-5cb4fee858ee // indirect    golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect    golang.org/x/mobile v0.0.0-20210924032853-1c027f395ef7 // indirect    golang.org/x/net v0.0.0-20210929193557-e81a3d93ecf6 // indirect    golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect    golang.org/x/text v0.3.7 // indirect    gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect)require (    github.com/davecgh/go-spew v1.1.1 // indirect    github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 // indirect    github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect    github.com/pkg/errors v0.9.1 // indirect    github.com/pmezard/go-difflib v1.0.0 // indirect    github.com/stretchr/testify v1.7.0 // indirect)
查看完整描述

1 回答

?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

因為在 Go 1.17 中,模塊圖已更改為啟用修剪和延遲加載。第二個塊包含間接依賴關系。require

https://golang.org/doc/go1.17#go-command

如果模塊指定 go 1.17 或更高版本,則模塊圖僅包含其他 go 1.17 模塊的直接依賴關系,而不包括其完全的傳遞依賴關系。[...]

[...]如果模塊在其 go.mod 文件中指定 go 1.17 或更高版本,則其 go.mod 文件現在包含一個顯式 require 指令,用于提供可傳遞導入包的每個模塊。(在以前的版本中,go.mod 文件通常只包含對直接導入的包的顯式要求。

由于在擴展的 Go 1.17 go.mod 文件中,顯式需求的數量可能要大得多,因此 go 1.17 模塊中對間接依賴項的新添加需求將保留在與包含直接依賴項的塊不同的需求塊中。

注意:您在問題中發布的文件在第一個 require 塊中具有依賴項。根據引用的文檔中的“新添加”一詞,我懷疑這是因為這些依賴項已經在那里列出并且沒有重新排列它們。如果您:go.mod//indirect//indirectgo mod tidy

  • 手動刪除其中一個

  • 和/或重新創建 Go 版本設置為 或更高的文件go.mod1.17

  • 和/或運行go mod tidy -go=1.17

然后它將在兩個塊中分離直接和依賴關系。無論如何,這是一種視覺上的便利,文檔并不要求創建兩個單獨的塊。//indirect


其他參考資料:


查看完整回答
反對 回復 2022-10-04
  • 1 回答
  • 0 關注
  • 267 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號