Skip to content

Introduction to Go Standard Library

At the time of writing this article, Go's release version has reached 1.21, and it has been more than a year since this site was first established.

Go's standard library is very rich (excluding data structures) and powerful. The API is very developer-friendly. Being proficient in using the standard library will be of great help to daily development. For example, you can develop an independent and complete web project without any external dependencies, using only net/http, html/template, and database/sql.

The content of the standard library has not been updated because there is really too much content. Therefore, the following will briefly summarize the functions of some commonly used standard libraries, so you can choose the ones you are interested in to learn more. Each standard library's package-level comments will explain in detail what the package is used for.

  • fmt: Package for handling formatted input and output
  • html: HTML template manipulation package
  • net: Provides a series of network operation packages, very powerful
  • flag: Command line argument parsing package
  • reflect: Reflection operation package
  • log: Built-in logging package
  • sort: Sorting operation package
  • regex: Regular expression package
  • image: Image manipulation package
  • time: Time manipulation package
  • unicode: Unicode character set manipulation package
  • unsafe: Provides pointer operations without type restrictions
  • syscall: System call package provided by the operating system
  • testing: Testing package, mainly used when writing tests
  • sync: Concurrency operation package
  • context: Context package
  • strconv: String conversion package
  • strings: String manipulation package
  • bytes: Byte slice manipulation package
  • maps: Map manipulation package
  • slices: Slice manipulation package
  • io: Defines a series of basic IO interfaces, such as commonly used Closer, Writer, etc., as well as some basic IO operation functions
  • io/fs: Defines a series of file system interfaces, which can be considered as an abstraction of the file system
  • os: Package for interacting with the operating system, providing a series of concrete functions, which can be simply understood as the concrete implementation of the above two
  • os/signal: Operating system signal package, used to listen for operating system signals, mainly used to achieve graceful shutdown of programs
  • os/exec: Operating system command package, used to execute operating system commands
  • os/user: Operating system user package, used to obtain operating system user information
  • bufio: Buffered IO read and write package
  • path: Package for handling slash-separated paths, such as URLs
  • path/filepath: Package for handling file paths
  • math: Mathematical operation package
  • math/bits: Bitwise operation package
  • math/cmplx: Complex number operation package, also provides some trigonometric function utilities
  • math/rand: Pseudo-random number package
  • math/big: High-precision large number calculation package
  • container/heap: Min-heap implementation
  • container/list: Doubly-linked list implementation
  • container/ring: Ring implementation
  • archive/zip: Zip compression archive package
  • archive/tar: Tar archive file package
  • compress: Compression algorithm implementation package, such as gzip, flate
  • database/sql: Package for interacting with databases
  • encoding: Package for handling encoding, with many sub-packages such as json, xml, and base64
  • crypto: Package for handling encryption, with many sub-packages such as sha1, rsa, etc.
  • go/ast: Package for mapping Go source code to abstract syntax tree
  • go/parser: Package for parsing Go source code into abstract syntax tree
  • go/importer: Provides access to importers
  • go/format: Go language formatting package
  • arena: Provides functionality for manual memory allocation and deallocation, in experimental stage
  • runtime: Runtime operation package, many operations in Go are implemented by this package