Packages and modules

Knowledge Videos

Short animated explainers, organised by subject.

Packages and modules

A package is a folder of Go files, a module is the whole project (go mod init, go.mod), how import works, and why a capital letter makes a name visible.

Transcript

As programs grow, you split them into files and packages. A package is a folder of Go files that belong together, like a room in a house.

A module is the whole project, like the house. You create one with go mod init and a name. It makes a go dot mod file that records the module's name and the Go version.

To use code from another package, you import it by its path, and call it with the package name, like converter dot Celsius To Fahrenheit.

A name is visible to other packages only if it starts with a capital letter. Celsius To Fahrenheit can be used, but a name that starts with a small letter stays private to its package.

Remember: a package is a folder of Go files, a module is the whole project, and a capital letter makes a name visible to other packages.

More in this series