我创建了一个小型 go 应用程序。几天前我已经从 go 1.15 升级到 1.17 并且我还升级了软件包go get -u
。更改后,我的 go.mod 文件中有 2 个 require 块。为什么?这是什么意思?没问题还是有什么东西坏了?
应用程序仍然可以正确构建。
go.mod 文件:
module github.com/jozo/simple-pomodoro
go 1.17
require (
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
)
因为在 Go 1.17 中,模块图已更改为启用修剪和延迟加载。第二require
块包含间接依赖项。
https://golang.org/doc/go1.17#go-command 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
第一个 require 块中的依赖项。我怀疑,根据引用文档中的“新添加”措辞,这是因为那些//indirect
依赖项已经在那里列出并且go mod tidy
不重新排列它们。如果你:
- 手动删除其中之一
- 和/或重新创建
go.mod
Go 版本设置为的文件1.17
或更高
- 和/或运行
go mod tidy -go=1.17
那么它将分离直接和//indirect
两个块中的依赖关系。无论如何,这是一种视觉上的便利,文档没有mandate创建两个单独的块。
附加参考:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)