Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Role of go.sum | Section
Practice
Projects
Quizzes & Challenges
Quiz
Challenges
/
Go Modules and Package Management

bookRole of go.sum

Scorri per mostrare il menu

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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 10

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Sezione 1. Capitolo 10
some-alt