Use Go's standard library for common functionality such as formatting, I/O, HTTP, JSON, concurrency and testing, and use third-party packages for specialised needs the library does not cover, such as database drivers, cloud SDKs or YAML. The standard library is stable, well tested and covered by the Go 1 compatibility promise, while third-party packages bring features at the cost of an extra dependency to maintain.
The practical rule is to start with the standard library and add a module only when it clearly saves effort or fills a gap.
The standard library is a set of packages that ship with the Go toolchain and need no installation. Commonly used ones are:
| Package | Purpose |
|---|---|
fmt | Formatted input and output |
strings, strconv, bytes | Text and byte handling |
os, io, bufio | Files, streams and buffered I/O |
net/http | HTTP client and server |
encoding/json | JSON encoding and decoding |
log/slog | Structured logging |
context, sync | Cancellation and synchronisation |
time | Time, durations, timers |
slices, maps | Generic helpers for slices and maps |
testing | Unit tests, benchmarks, fuzzing |
Everything here is imported by path and needs no entry in go.mod.
A complete HTTP server with JSON needs no external code:
The GET /hello pattern with a method needs Go 1.22 or later. On older versions, register /hello and check r.Method yourself.
Third-party packages are ordinary Go modules published in public or private repositories and imported by their module path. They are most useful for:
database/sql.A typical addition looks like this:
The standard library has no YAML parser, so this is a legitimate use of an external module.
| Aspect | Standard library | Third-party package |
|---|---|---|
| Stability | Go 1 compatibility promise | Depends on the maintainers |
| Installation | Ships with Go | go get and a go.mod entry |
| Security updates | With Go releases | Follow each project's releases |
| Feature depth | Broad but intentionally minimal | Often richer and specialised |
| Learning curve | One consistent style | Varies per package |
| Supply-chain risk | Lowest | Grows with each dependency |
std before searching for a module.go.mod, review updates and run govulncheck ./... in CI.Avoid third-party replacements for things the standard library now handles well, such as basic routing since Go 1.22 or logging with log/slog since Go 1.21.
For many services, yes. Add modules for drivers, SDKs and formats that are missing, not for convenience alone.
They are as safe as their maintainers and your review. Prefer well-maintained modules, read the dependency list and scan with govulncheck.
Run go list -m all for modules and go list -deps ./... for every imported package.
Yes. Add a replace directive in go.mod that points the module path to your fork or a local directory.
The Go standard library gives you tested, stable building blocks for common work, and third-party packages cover specialised needs. Start with the standard library, add a module only for a real gap, keep it behind a small interface, and monitor it for updates and vulnerabilities.