Skip to content

Standard Library

Go’s batteries-included standard library

Section titled “Go’s batteries-included standard library”

One of Go’s defining characteristics is that the language ships with a comprehensive standard library — no npm install, no pip install, no Maven coordinates required for the vast majority of everyday tasks. The library covers HTTP servers and clients, JSON encoding, cryptography, file I/O, text processing, concurrency primitives, and much more. This philosophy keeps dependency trees shallow, binaries self-contained, and upgrade risks low.

The table below shows what this module covers and which package delivers it.

TopicPackage(s)Lesson
Formatted I/O, text, numbersfmt, strings, strconvfmt & strings
Dates, durations, timerstimetime
JSON marshaling / unmarshalingencoding/jsonencoding/json
Streaming I/O, scanningio, bufioio & bufio

Real Go programs reach for fmt.Println, strings.Split, time.Now, and json.Marshal within the first few lines. Understanding these packages deeply means you will recognise idiomatic Go in any codebase you encounter, and you will reach for the right tool instead of pulling in an extra dependency.

The snippet below touches all four areas in a single main function. Read the output, then trace each call back to its package.

package main
import (
"encoding/json"
"fmt"
"strings"
"time"
)
func main() {
// fmt — formatted output
fmt.Println("Hello, Go!")
fmt.Printf("Pi is approximately %.4f\n", 3.14159)
msg := fmt.Sprintf("2 + 2 = %d", 4)
fmt.Println(msg)
// strings — text manipulation
s := "the quick brown fox"
fmt.Println(strings.ToUpper(s))
fmt.Println(strings.Contains(s, "fox"))
fmt.Println(strings.Join(strings.Split(s, " "), "-"))
// time — fixed date for deterministic output
t := time.Date(2024, 1, 2, 15, 4, 5, 0, time.UTC)
fmt.Println(t.Format("2006-01-02"))
// encoding/json — marshal a struct
type Point struct {
X int `json:"x"`
Y int `json:"y"`
}
p := Point{X: 3, Y: 7}
b, _ := json.Marshal(p)
fmt.Println(string(b))
}
Which package provides fmt.Sprintf?
Go's standard library is designed so that most everyday programs need:
Which package would you use to convert the string "42" to the integer 42?
What does json.Marshal return when it succeeds?