Go Modules

July 8, 2022   

I’ve learned go modules multiple times and I cronically forget how they work. This not hopefully helps me remember them.

All go software needed to be in the GOPATH. This was fine but it made versioning difficult.

  • A go module can contain multiple packages inside.

  • A go module is versioned

  • A go repository can contain multiple packages.

  • A go repository is versioned (git)

  • A go repository can contain multiple modules

Now you can place go software outside your go path by creating the module.

go mod init my-module

The traditional format for my-module is “github.com/ajmaidak/my-module” but go modules allow for any name.

go.mod contains all the depenancy information (v1.2.0).

go.sum contains the cryptographic hash for your package version this is used to assert the versions have not ben mutated.

go.sum keeps older versions that we used before to allow you to revert versions to something you can trust.

go.mod = what you depend on

go.sum = signatures of the modules you are using.

go get -u github.com/sirupsen/logrus can be used to upgrade deps

go mod tidy will update everything including tests?

go mod vendor will copy the modules you are using into a vendor folder.