【Golang】依赖 - Checksum Mismatch

Posted by 西维蜀黍 on 2020-09-06, Last Modified on 2023-02-28

Context

执行 go mod tidy 报错

$ go mod tidy
go: verifying github.com/docker/docker@v1.13.1: checksum mismatch

Expect (go version go1.12.9 darwin/amd64):

$ go mod tidy -v
go: downloading github.com/panjf2000/ants v1.2.0
go: extracting github.com/panjf2000/ants v1.2.0

Actual (go version go1.13 darwin/amd64)

$ go mod tidy -v
verifying github.com/panjf2000/ants@v1.2.0: checksum mismatch
        downloaded: h1:Ufw4aDz9RqH1RVblx2W9L9Uv5vSX5apbX5+peR7LQ5k=
        sum.golang.org: h1:pMQ1/XpSgnWx3ro4y1xr/uA3jXUsTuAaU3Dm0JjwggE=

SECURITY ERROR
This download does NOT match the one reported by the checksum server.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.

For more information, see 'go help module-auth'.

解决办法

Solution 1

There is a fundamental solution to this kind of issue:

$ go clean -modcache
# Remove go.sum
$ rm go.sum

# Then re-generate go.sum
$ go mod tidy

Solution 2

Important thing: Close your IDE! I had that problem with GoLand. Close IDE and repeat the steps:

$ cd /another/path
$ go clean -modcache
$ cd /project/path
$ go mod tidy

Solution 3

How resolve issue step by step (macOS):

$ sudo go clean -modcache
$ git checkout go.sum
$ go mod tidy -v

for Linux:

$ cd /another/path
$ go clean -modcache
$ cd /project/path
$ go mod tidy

Reference