Combine Go's standard library with third-party packages by letting the standard library do the core work (HTTP, JSON, logging, concurrency, testing) and adding a module only for a gap it does not fill, such as a database driver, a message queue client or a specialised parser. You fetch third-party code with Go modules, pin versions in go.mod, and keep the dependency surface small.
This article walks through a small service that mixes both, then shows how to add, upgrade and audit dependencies safely.
Go ships a broad standard library, so many programs need few or no external modules.
| Task | Standard packages |
|---|---|
| HTTP servers and clients | net/http (with method and path patterns in ServeMux since Go 1.22) |
| JSON, XML, CSV | encoding/json, encoding/xml, encoding/csv |
| Structured logging | log/slog (Go 1.21+) |
| Concurrency | sync, context, sync/atomic |
| Databases | database/sql (interface only, you add a driver) |
| Cryptography and TLS | crypto/... |
| Testing and benchmarks | testing, net/http/httptest |
| Slices, maps, sorting | slices, maps, cmp (Go 1.21+) |
| Templates | html/template, text/template |
Reaching for a package from this list first gives you code that is maintained with the language, covered by the Go compatibility promise and free of extra supply-chain risk.
Add an external module when the standard library deliberately leaves a gap:
database/sql needs one (for example github.com/jackc/pgx/v5 for PostgreSQL).flag is not enough.Do not add a module for something the standard library already does. A router is a common example: since Go 1.22, http.ServeMux handles methods and wildcards, which is enough for many APIs.
This program uses only the standard library for the HTTP server, JSON and logging, and one external module for the database driver import. The driver registers itself with database/sql.
The routing, JSON, logging, timeouts and database/sql API all come from the standard library. Only the driver is external, so swapping databases later means changing one import and one connection string.
Modules are the official dependency system. Typical commands:
go.mod records the minimum required version of each module, and go.sum stores checksums that the toolchain verifies on download, so builds are reproducible. Go uses minimal version selection, which picks the lowest version that satisfies all requirements instead of the newest.
Before adding a package, check these points:
go mod graph to see.Then keep it healthy: run govulncheck ./... in CI to find known vulnerabilities that your code actually calls, and upgrade regularly with go get -u followed by your test suite.
Run go get module/path@version inside a module, then import it. go mod tidy cleans up go.mod and go.sum.
Prefer it when it is enough. It has no extra dependency risk, and Go 1.22 routing covers many APIs. Choose a framework only for features you would otherwise rebuild.
go.mod lists required modules and versions. go.sum holds cryptographic hashes used to verify downloaded module contents.
Yes. Set GOPRIVATE to the module path prefix so the toolchain skips the public proxy and checksum database for it.
Build on the standard library for everything it does well, add third-party modules for real gaps such as drivers and SDKs, and manage them with Go modules. Vet each dependency, wrap it behind a small interface where practical, and run govulncheck regularly.