Go (Golang) Modules Tutorial



Go (Golang) Modules Tutorial

Go (Golang) Modules Tutorial

Go modules is the newest and very powerful dependency management system for Go. It’s used to create, import and manage group of Go packages and ensure that we have reproducible and deterministic builds.

In this episode we are going to see how we can initialise Go modules for a project, how to add, remove, upgrade, downgrade dependencies in Go and what tools the Go toolchain has to make our job easier.

If you want a quick and easy way to see how to work with Go mod you can use go help mod which exposes a list of thorough in-terminal documentation manuals.

How to Initialise Go modules in your project
go mod init example.com/bob/golang-project

How to add a dependency
go get github.com/pkg/[email protected]

How to upgrade a dependency and all its dependencies recursively
go get -u github.com/pkg/errors@latest

How to remove stale go.sum entries
go mod tidy

How to upgrade all dependencies in a project
go get -u ./…

Go Modules – https://blog.golang.org/using-go-modules
Go Modules Queries – https://golang.org/ref/mod#version-queries

Source Code – https://play.golang.org/p/Nfo7StDWxN1

How to upgrade dependencies in Go – https://golang.cafe/blog/how-to-upgrade-golang-dependencies.html

💼 Golang Cafe – https://golang.cafe
📬 Golang Cafe Jobs Newsletter – https://golang.cafe/newsletter
🐦 Golang Cafe Twitter – https://twitter.com/golangcafe
📣 Telegram Channel – https://t.me/golangcafe
🙏 Found this video useful? Help me make more by donating $5.00 – https://golang.cafe/5USD

Comments are closed.