3 回答

TA貢獻1772條經驗 獲得超8個贊
導致go.sum
文件中寫入每個依賴項總和哈希值。與您的文件相關的一個go.mod
,以及從您已導入的模塊導入的一個。嘗試運行go mod tidy
以減少導入的模塊,您的go.mod
文件將包含一些//indirect
導入,即您導入的模塊在內部使用的模塊。

TA貢獻1790條經驗 獲得超9個贊
go.sum
包含特定模塊版本內容的預期加密校驗和。每次使用依賴項時,如果缺少或需要匹配 go.sum 中的現有條目,則將其校驗和添加到 go.sum 中。
每個包/模塊都是依賴項,每個依賴項都意味著用校驗和來維護,go.sum
因此無論是包還是模塊,它都會被維護。
源文件將下載到$GOPATH/src
相應的目錄中。

TA貢獻1873條經驗 獲得超9個贊
也許Golang源碼可以解釋原因:
func (r *codeRepo) legacyGoMod(rev, dir string) []byte {
// We used to try to build a go.mod reflecting pre-existing
// package management metadata files, but the conversion
// was inherently imperfect (because those files don't have
// exactly the same semantics as go.mod) and, when done
// for dependencies in the middle of a build, impossible to
// correct. So we stopped.
// Return a fake go.mod that simply declares the module path.
return []byte(fmt.Sprintf("module %s\n", modfile.AutoQuote(r.modPath)))
}
來自此處的代碼: https: //github.com/golang/go/blob/acac535c3ca571beeb168c953d6d672f61387ef1/src/cmd/go/internal/modfetch/coderepo.go#L857
↓ VSCode 打開/usr/local/go/src
:
定位到
cmd/go/internal/modfetch/coderepo.go
,向 func 添加斷點legacyGoMod
找到
cmd/go/internal/modfetch/coderepo_test.go
,按 F5稍等片刻,停在斷點處
- 3 回答
- 0 關注
- 224 瀏覽
添加回答
舉報