go mod verify: Usage & Common CI Errors
Confirm your cached modules have not been modified.
go mod verify checks that the dependencies stored in the module cache still match the cryptographic hashes recorded in go.sum, catching tampering or corruption.
What it does
Re-hashes each module in the cache and compares against go.sum. On success it prints "all modules verified"; on failure it names the module whose contents changed and exits non-zero.
Common usage
go mod verify # verify cached modules vs go.sumCommon CI error: a module fails verification
go mod verify reports "example.com/pkg v1.2.3: dir has been modified" because cached source was altered or corrupted. Fix: clear the cache with go clean -modcache, re-download with go mod download, and re-run verify. If it persists, the upstream content changed and go.sum must be investigated, not blindly updated.