Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Role of go.sum | Section
Go Modules and Package Management

bookRole of go.sum

Sveip for å vise menyen

When working with Go modules, you will notice the presence of a go.sum file in your project directory. The go.sum file plays a crucial role in ensuring the security and reproducibility of your builds. It records cryptographic hashes of the exact content of every module version your project depends on, including both direct and indirect dependencies. Whenever you run commands like go mod tidy, go build, or go test, Go verifies that the downloaded modules match the hashes stored in go.sum. If there is a mismatch, the command fails, alerting you to potential tampering or corruption. This mechanism helps protect your project from supply chain attacks and accidental inconsistencies.

go.mod

go.mod

main.go

main.go

go.sum

go.sum

copy
12345
module myproject go 1.21 require github.com/fatih/color v1.13.0

You should always commit your go.sum file to version control along with go.mod. This practice guarantees that everyone working on the project, as well as automated build systems, can verify the integrity of all dependencies. If the go.sum file is missing, Go will attempt to regenerate it, but this opens up the possibility of downloading altered or malicious dependencies without detection. If the file is altered—intentionally or accidentally—Go will detect the mismatch between the expected and actual hashes, preventing the build and alerting you to the inconsistency. This makes go.sum a critical part of secure and reproducible Go development.

question mark

What happens if the hash of a downloaded module does not match the entry in go.sum?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 10

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Seksjon 1. Kapittel 10
some-alt