HowtoGo
Home / Standard Library / Standard Library Overview
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.

Reading a signature
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!")

Using a type the package declares
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.

Calling a method on that type
(*Buffer) receiver what you call it onWriteString method name (s string) parameters var name(n int, err error) results returns a value and error
PackageDescription
bufioBuffered I/O, and scanning by line, word, or rune
bytesByte slice manipulation, plus Buffer and Reader
cmpOrdering and comparison helpers for generic code
contextCancellation, deadlines, and request-scoped values
cryptoThe Hash interface shared by every hashing subpackage
database/sqlSQL database access, with a driver behind it
embedFiles compiled into the binary
encoding/base64Base64 encoding and decoding, standard and URL-safe
encoding/jsonJSON encoding and decoding
errorsWrapping, checking, and comparing errors
execRunning external commands
flagCommand-line flag parsing
fmtFormatted I/O: printing, building strings, and reading input
html/templateContext-aware, auto-escaping HTML templating
imageDecoding, encoding, and manipulating images
ioReader, Writer, and the primitives built on them
io/fsThe read-only filesystem interface
io/ioutilThe superseded helpers, and what replaced each one
iterThe function types behind every range-over-func
logTimestamped output to stderr
mapsGeneric functions over any map
mathBasic math functions and constants
netTCP, UDP, and Unix sockets, and DNS lookups
net/httpHTTP client and server
osFiles, environment variables, and process state
pathSlash-separated paths, for URLs and fs.FS
path/filepathFilesystem paths, with the host's own separator
reflectRuntime type introspection
regexpRegular expressions
runtimeScheduler, collector, and runtime information
slicesGeneric operations over slices
sortSorting slices and user-defined collections
strconvConversions between strings and basic types
stringsString manipulation
syncMutexes, WaitGroups, and other concurrency primitives
text/templateData-driven text generation
timeInstants, durations, timers, and tickers
unicodeUnicode character classification and case conversion

A few functions to start with

FunctionDescription
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