Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Module-Aware Build and Test | Section
Practice
Projects
Quizzes & Challenges
Вікторини
Challenges
/
Go Modules and Package Management

bookModule-Aware Build and Test

Свайпніть щоб показати меню

When you use Go modules, the go build and go test commands become module-aware, meaning they automatically manage dependencies based on your go.mod file. This approach frees you from manually managing your GOPATH or copying dependencies into your project. When you run go build, Go reads your go.mod file, fetches any needed dependencies from their sources, and builds your code using exactly those versions. Similarly, go test uses the module context to ensure all tests run with the correct dependencies, matching the specified versions in go.mod.

main.go

main.go

main_test.go

main_test.go

copy
1234567891011
package main import ( "fmt" "github.com/google/uuid" ) func main() { id := uuid.New() fmt.Println("Generated UUID:", id) }

With module-aware commands, you gain several benefits. Builds are reproducible because every dependency and its version are recorded in go.mod and go.sum, so anyone building your code gets the same results. Testing is isolated to your project's declared dependencies, which reduces unexpected failures from changes in the environment or global workspace. This makes it easier to collaborate, automate builds, and maintain consistent results across different machines and CI systems.

question mark

How does module-aware mode change the behavior of go build and go test?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 3
some-alt