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.
| Topic | Package(s) | Lesson |
|---|---|---|
| Formatted I/O, text, numbers | fmt, strings, strconv | fmt & strings |
| Dates, durations, timers | time | time |
| JSON marshaling / unmarshaling | encoding/json | encoding/json |
| Streaming I/O, scanning | io, bufio | io & bufio |
Why standard library first?
Section titled “Why standard library first?”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.
A runnable tour
Section titled “A runnable tour”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))}Loading Go runtime (first run only, ~8 MB)…