Go Tutorial: Packages & Modules
Stop reinventing the wheel. Use Go's rich standard library and the entire open-source ecosystem.
You are not alone
Every program you have written so far has used at least one package: `fmt`. You imported it, called its functions, and moved on.
But Go ships with hundreds of packages covering everything from string manipulation to cryptography, HTTP servers to JSON encoding. And beyond the standard library, thousands of open-source packages are one `go get` away.
Understanding packages and modules is what takes you from writing scripts to building real software.
Twelve steps.
What you'll learn in this Go packages & modules tutorial
This interactive Go tutorial has 12 hands-on exercises. Estimated time: 22 minutes.
- What is a package — Every Go file starts with a `package` declaration. It tells Go which package this file belongs to.
- Importing standard library packages — Go's standard library is huge. You do not install anything — it comes with Go.
- The strings package — The `strings` package handles almost every text operation you will ever need.
- The math package — The `math` package gives you mathematical constants and functions.
- The time package — The `time` package handles dates, times, durations, and formatting.
- The os package — The `os` package lets you interact with the operating system: environment variables, command-line arguments, file system…
- Exported vs unexported — In Go, whether something is public or private is decided by a single rule:
- What is a module — A module is a collection of Go packages with a shared identity and version.
- Using a third-party package — Beyond the standard library, Go's ecosystem has thousands of packages at `pkg.go.dev`.
- Import aliases — You can give an imported package a different name using an alias:
- Blank import — Sometimes you import a package purely for its side effects — it registers something when it loads, but you never call it…
- Build a string toolkit — No starter code.
Go Packages & Modules concepts covered
- You are not alone