3 回答

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
導(dǎo)致go.sum
文件中寫入每個(gè)依賴項(xiàng)總和哈希值。與您的文件相關(guān)的一個(gè)go.mod
,以及從您已導(dǎo)入的模塊導(dǎo)入的一個(gè)。嘗試運(yùn)行go mod tidy
以減少導(dǎo)入的模塊,您的go.mod
文件將包含一些//indirect
導(dǎo)入,即您導(dǎo)入的模塊在內(nèi)部使用的模塊。

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

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊
也許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 添加斷點(diǎn)legacyGoMod
找到
cmd/go/internal/modfetch/coderepo_test.go
,按 F5稍等片刻,停在斷點(diǎn)處
- 3 回答
- 0 關(guān)注
- 214 瀏覽
添加回答
舉報(bào)