The Go standard library is the set of packages shipped with the Go toolchain and maintained by the Go team under the Go 1 compatibility promise. Custom libraries are any other packages: ones you write inside your own module, ones your company shares, and open-source modules from the community. Prefer the standard library when it does the job, and add a custom or third-party library when you need functionality the standard library does not offer.
This choice affects build size, security exposure, upgrade effort and how easily other Go developers can read your code.
The standard library is imported by path, with no go get step and no entry in go.mod. It covers most of what a backend service or command-line tool needs:
| Area | Packages |
|---|---|
| Formatting and text | fmt, strings, strconv, text/template, regexp |
| I/O and files | io, bufio, os, io/fs, path/filepath |
| Networking and web | net, net/http, net/url, crypto/tls |
| Data formats | encoding/json, encoding/xml, encoding/csv, encoding/gob |
| Concurrency | sync, sync/atomic, context |
| Logging | log, log/slog (structured logging, Go 1.21+) |
| Collections | slices, maps (Go 1.21+), container/list, container/heap |
| Databases | database/sql (interface only, you add a driver) |
| Testing | testing, net/http/httptest, testing/fstest |
Since Go 1.22 the net/http router supports method and path-parameter patterns such as GET /users/{id}, which removes the main reason many projects used a third-party router for small services.
This is a complete JSON API using only the standard library: routing, JSON encoding and structured logging.
"Custom library" covers three different things, and it helps to separate them.
example.com/shop/internal/billing. You control the code and the internal directory stops outside modules from importing it.github.com/jackc/pgx/v5 (PostgreSQL driver), github.com/spf13/cobra (CLI framework) or golang.org/x/sync/errgroup.The golang.org/x/... modules are maintained by the Go team but sit outside the standard library. They have a looser compatibility guarantee and are a good middle ground when the standard library lacks a feature.
Go modules record the exact version in go.mod and checksums in go.sum, so builds are reproducible.
| Aspect | Standard library | Custom or third-party library |
|---|---|---|
| Installation | Bundled with Go | go get and a go.mod entry |
| Compatibility | Go 1 promise: existing code keeps compiling | Depends on the maintainer and semantic versioning |
| Maintenance | Go team, released with each Go version | You or the maintainers, on their own schedule |
| Security | Fixed in Go point releases | You must track advisories and update each module |
| Scope | General purpose, deliberately conservative | Specialised, can be opinionated or feature-rich |
| Build and binary impact | Only imported packages are linked | Adds code and transitive dependencies |
| Learning curve | Documented at pkg.go.dev, familiar to every Go developer | Varies |
The Go team adds to the standard library slowly. That is why some well-known needs are met outside it: PostgreSQL drivers, YAML parsing, rich CLI frameworks, and gRPC.
Work through these questions in order.
pkg.go.dev/std first. slices.Sort, maps.Keys, slog, net/http routing and encoding/json replace many older helper libraries.golang.org/x package solve it? These are the lowest-risk additions./v2, /v5).govulncheck ./... regularly. It reports known vulnerabilities in the standard library and in the modules you actually call.Keep a custom package small and focused, name it after what it provides, and put anything you do not want others to import under internal/:
(Add import "fmt" at the top of the file.) A doc comment starting with the package name appears on pkg.go.dev and in go doc.
Prefer it when it covers your need, because it has the strongest stability and security story. Do not rewrite a well-tested driver or protocol implementation yourself just to avoid a dependency.
golang.org/x packages part of the standard library?No. They are maintained by the Go team but are separate modules with their own versions. Some of them, such as x/exp/slices, later moved into the standard library.
Run govulncheck ./... and keep modules updated with go get -u ./... followed by tests. Review go.sum changes in code review.
Yes. go mod vendor copies them into a vendor/ directory, and go build -mod=vendor uses it. This helps with offline builds.
The standard library gives you a stable, well-documented base that covers HTTP, JSON, logging, concurrency and testing. Custom libraries, whether your own packages or community modules, fill the gaps. Start with the standard library, move to golang.org/x and then to vetted third-party modules, and scan dependencies with govulncheck.