Package Management in Go for NPM users

Introduction

Installing a Dependency

Similar to npm install you have go get url@version.

After installing a dependency, if you look at the go.mod file, you might see some of the dependencies listed as

github.com/go-chi/chi@v4.0.1+incompatible // indirect

When you install a package, you might see that it created go.sum file in the repository which contains the cryptographic checksums of the packages installed which is used for validation purposes.

Caching the dependencies

Running go mod download will download all the dependencies and cache them locally which could make CI faster.

Removing unused packages

Updating Package Versions

Substituing Imported Modules

Point a required module to your own fork or even local file path using replace directive:

go mod edit -replace github.com/go-chi/chi=./packages/chi

Remove the replacement

go mod edit -dropreplace github.com/go-chi/chi