我已经创建了小型围棋应用程序.几天前,我把go 1.15升级到了1.17,还升级了go get -u个软件包.更改后,我的围棋中有两个require块.mod文件.为什么?这是什么意思?还好吗,还是有东西坏了?

应用程序仍能正确构建.

go.mod file:

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中,模块图已更改为启用修剪和延迟加载.第二个百个挡路包含间接依赖.

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

如果模块指定go 1.17或更高,the module graph includes only the immediate dependencies of other go 1.17 modules,则不是它们的完全可传递依赖项.[...]

[.]如果模块在其go.mod文件中指定go 1.17或更高版本,则其go.mod文件现在包含an explicit require directive for every module that provides a transitively-imported package.(在以前的版本中,go.mod文件通常只包含对直接导入的包的明确要求.)

因为在扩展的GO 1.17go.mod文件中显式需求的数量可能要大得多,所以在GO 1.17模块中新添加的关于间接依赖的需求被维护在separate require block from the block containing direct dependencies.%的GO 1.17go.mod文件中

注意:你在问题中发布的go.mod个文件在第一个require块中有//indirect个依赖项.我怀疑,从引用的文档"新增"术语推断,这是因为这//indirect个依赖项已经在那里列出,而go mod tidy个没有重新排列它们.如果你:

  • 手动删除其中一个
  • 和/或重新创建GO版本设置为1.17或更高版本的go.mod文件
  • 和/或运行go mod tidy -go=1.17

然后,它将正确地分离两个块中的直接依赖项和//indirect个依赖项.至少这是我在我的项目中经验性地看到的.还在寻找文件中更明确的提法.

Go相关问答推荐

如何使用GRPC UnaryClientInterceptor中的`maily`参数?

map 中的多个函数类型,Golang

使用ciph.AEAD.Seal()查看内存使用情况

如何确定泛型类型在运行时是否可比较?

`docker system df` 与 `/system/df` (docker api 端点)

调用库和直接操作效率有区别吗?

如何使用 html/template 在 golang 中运行一个范围内的范围

无法读取postman 中的表单数据

仅使用公共 api 对 alexedwards/scs 进行简单测试

缺少签名帮助文档

GOLANG:为什么 SetDeadline/SetReadDeadline/SetWriteDeadline 在使用 os.File.Fd() 时对文件不起作用?

如何在 Docker 容器中使用私有存储库进行身份验证

从 os.stdout 读取

如何使用 Go 获取 X11 中的窗口列表

如何使用 math/big 对 bigInt 进行取模?

具有相同提前返回语句的函数的不同基准测试结果

Go 加密库创建的 PKCS1 公钥与openssl rsa ...之间的区别

具有多个嵌入式 struct 的 Go MarshalJSON 行为

如何解决在mac m1中运行gcc失败退出状态1?

关于GO的几个问题