Standard Library
Standard Library Overview
A quick run-down on what you're reading and how to read it. The official go doc and pkg.go.dev remain the complete reference for those.
Every page in this section is a list of signatures, and they all read the same way: the package it came from, the name you call, what you pass in, and what comes back.
func keyword Copy name (dst Writer, src Reader) parameters name, then type(w int64, err error) results returns a value and error
A package also declares its own Types. You get one from a function rather than building it yourself, then call methods on it like so buf.WriteString("Hi!")
var keyword buf declare variable bytes package name .Buffer Type
A row that opens with a type in parentheses is a method. You call it on a value of that type rather than on the package, so you need one of those first. The star means it wants a pointer, and Go takes the address for you when you call it on a variable.
(*Buffer) receiver what you call it onWriteString method name (s string) parameters var name(n int, err error) results returns a value and error
| Package | Description |
|---|---|
| bufio | Buffered I/O, and scanning by line, word, or rune |
| bytes | Byte slice manipulation, plus Buffer and Reader |
| cmp | Ordering and comparison helpers for generic code |
| context | Cancellation, deadlines, and request-scoped values |
| crypto | The Hash interface shared by every hashing subpackage |
| database/sql | SQL database access, with a driver behind it |
| embed | Files compiled into the binary |
| encoding/base64 | Base64 encoding and decoding, standard and URL-safe |
| encoding/json | JSON encoding and decoding |
| errors | Wrapping, checking, and comparing errors |
| exec | Running external commands |
| flag | Command-line flag parsing |
| fmt | Formatted I/O: printing, building strings, and reading input |
| html/template | Context-aware, auto-escaping HTML templating |
| image | Decoding, encoding, and manipulating images |
| io | Reader, Writer, and the primitives built on them |
| io/fs | The read-only filesystem interface |
| io/ioutil | The superseded helpers, and what replaced each one |
| iter | The function types behind every range-over-func |
| log | Timestamped output to stderr |
| maps | Generic functions over any map |
| math | Basic math functions and constants |
| net | TCP, UDP, and Unix sockets, and DNS lookups |
| net/http | HTTP client and server |
| os | Files, environment variables, and process state |
| path | Slash-separated paths, for URLs and fs.FS |
| path/filepath | Filesystem paths, with the host's own separator |
| reflect | Runtime type introspection |
| regexp | Regular expressions |
| runtime | Scheduler, collector, and runtime information |
| slices | Generic operations over slices |
| sort | Sorting slices and user-defined collections |
| strconv | Conversions between strings and basic types |
| strings | String manipulation |
| sync | Mutexes, WaitGroups, and other concurrency primitives |
| text/template | Data-driven text generation |
| time | Instants, durations, timers, and tickers |
| unicode | Unicode character classification and case conversion |
A few functions to start with
| Function | Description |
|---|---|
fmt.Sprintf fmt.Sprintf("%d", 42) | Formats and returns a string |
strings.Split / Join strings.Split("a,b,c", ",") | Splits a string into a slice or joins a slice into a string |
slices.Sort slices.Sort(nums) | Sorts a slice of ordered values in place |
os.Getenv os.Getenv("API_KEY") | Reads an environment variable, empty string if unset |
io.Copy io.Copy(dst, src) | Copies from src to dst until EOF |
time.Now time.Now() | Returns the current local time |
errors.Is errors.Is(err, os.ErrNotExist) | Reports whether an error chain contains a target error |
regexp.MatchString regexp.MatchString("a.*b", "acb") | Reports whether a string matches a regular expression |