go - “go mod tidy”与“go build”的行为
问题描述
假设我有一个具有以下结构的项目:
+-- app/
+-- otherstuff/
+-- test/
+-- go.mod
+-- go.sum
+-- main.go
我可以通过运行确保go.mod
不包含未使用的依赖项go mod tidy
:
# 1) Verify that no dependency containing the name "modern-go" is found on go.mod
$ grep 'modern-go' go.mod
<-- Empty (nothing found) (OK)
# 2) Run "go mod tidy", verify that nothing changes (i.e. go.mod is already clean)
$ go mod tidy -v
unused github.com/modern-go/concurrent
unused github.com/modern-go/reflect2
<-- messages above are displayed, but go.mod did not change
# 3) Verify that go.mod did not change
$ grep 'modern-go' go.mod
<-- Empty (nothing found) (OK)
现在,如果我运行go build
,go.mod
会更新:
# 4) Run "go build"
$ go build
# 5) go.mod was updated by "go build":
$ grep 'modern-go' go.mod
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
我无法弄清楚这里发生了什么。我预计go mod tidy
会go.mod
保持干净的状态,go build
因此运行不会改变它。
有任何想法吗?
解决方案
推荐阅读
- google-cloud-networking - 如何验证 Cloud CDN 响应是否是缓存命中(或来自 CDN)
- python - 刮掉 MP4 链接
- typescript - 有谁知道如何通过 Typescript 在 API 中使用 delete 方法?
- c++ - 如何检查 GENERIC lambda 是否可以使用某种输入参数类型调用?
- go - 访问结构属性的空接口以避免代码重复
- c - 从命令行迭代 ls 程序的选项
- sql - 收到此错误:无法绑定多部分标识符“c.hrmort”
- webpack - Webpack 不压缩 javascript
- reactjs - react.js & tailwind.css 项目没有正确部署到heroku
- javascript - 使用 jQuery 在 JSON/Array/Object 中选择存储选项