The Go standard library is a collection of core packages providing essential functionality for networking, serialization, system operations, and static analysis. It is designed for portability, offering consistent interfaces across operating systems while abstracting platform-specific details.
The standard library is located in the src/ directory of the Go repository. For details on how these packages are built, see Build System.
The standard library is organized into several key subsystems. The following diagram bridges high-level functional areas to their primary code entities, including basic data manipulation and core networking types.
Standard Library Subsystems and Primary Code Entities
Sources: src/net/http/server.go164-167 src/net/http/transport.go98-115 src/net/http/request.go114-132
net/http)The net/http package provides a robust implementation of HTTP/1.1 and HTTP/2. It is built around the Handler interface for servers and the RoundTripper interface for clients.
ServeMux for routing and ResponseWriter src/net/http/server.go97-162 to construct responses. The Server struct src/net/http/server.go2754-2755 (located in server.go) manages the lifecycle of listeners and connections.Client struct src/net/http/client.go59-108 uses a Transport src/net/http/transport.go98-115 to manage connection pooling, proxy settings, and TLS configuration. The Transport implements RoundTripper src/net/http/client.go118-144ServeFile src/net/http/fs.go731-733 and FileServer src/net/http/fs.go852-854 utilizing the FileSystem interface src/net/http/fs.go106-108For details, see HTTP Server and Client.
HTTP Core Interface Relationships
Sources: src/net/http/server.go89-91 src/net/http/server.go97-162 src/net/http/request.go114-132 src/net/http/client.go118-144 src/net/http/transport.go98-115 src/net/http/fs.go106-108
Go supports a wide array of serialization formats, ranging from traditional binary formats to modern JSON v2.
archive/zip and archive/tar packages provide streaming access to file collections.encoding/json package and the new encoding/json/v2 src/encoding/json/v2/doc.go5-10 experiment, which introduces the jsontext package src/encoding/json/v2/arshal_test.go32-33 for low-level tokenized processing.base64, hex, and gob is provided for efficient data interchange.For details, see Serialization and Encoding.
Sources: src/encoding/json/v2/doc.go5-10 src/encoding/json/v2/arshal_test.go32-33
The standard library includes a full suite of packages for parsing, type-checking, and inspecting Go source code.
go/parser and go/ast allow tools to build an Abstract Syntax Tree from source. go/types performs full type checking.reflect package allows programs to inspect their own structure at runtime.weak for weak pointers and structs for marker types.For details, see Static Analysis and Tooling.
Go's security packages provide high-level abstractions for common cryptographic tasks, with a focus on safe defaults.
crypto/tls implements the Transport Layer Security protocol.lib/fips140/.For details, see Cryptography and Security.
The standard library includes the testing package, integrated with the go test command.
| Type | Code Entity | Purpose |
|---|---|---|
| Unit Test | testing.T | Standard functional testing src/net/http/serve_test.go45-48 |
| Benchmark | testing.B | Performance measurement. |
| Deterministic | testing/synctest | Deterministic testing of concurrent code src/net/http/serve_test.go46-48 |
The synctest package src/net/http/clientserver_test.go139-145 allows for isolated time and concurrency management via "bubbles."
Sources: src/net/http/serve_test.go45-48 src/net/http/clientserver_test.go139-145