Standard Library Essentials

beginner go stdlib

Go’s standard library is famously “batteries included” — HTTP servers, JSON, crypto, testing, all ship with the language. We rarely need third-party packages for the basics.

In simple language, a lot of stuff that needs an npm install in Node is just there in Go.

This is a quick tour of the packages we reach for daily.

fmt — formatting and printing

The package we use on day one. Printing, formatting strings, scanning input.

fmt.Println("hello")                 // print with a newline
s := fmt.Sprintf("%s is %d", "Go", 15) // build a string, don't print it
fmt.Printf("%v\n", []int{1, 2, 3})   // %v = default format of any value
fmt.Printf("%+v\n", struct{ X int }{1}) // %+v adds field names: {X:1}

The verbs to remember: %v (any value), %+v (with field names), %d (int), %s (string), %T (the type itself).

strings & strconv — text and conversions

strings handles text manipulation. strconv converts between strings and numbers.

strings.Contains("golang", "go")     // true
strings.Split("a,b,c", ",")          // ["a" "b" "c"]
strings.ToUpper("hi")                // "HI"
strings.TrimSpace("  hi  ")          // "hi"

n, _ := strconv.Atoi("42")           // string → int (Atoi = ASCII to int)
str := strconv.Itoa(42)              // int → string
f, _ := strconv.ParseFloat("3.14", 64) // string → float64

Don’t confuse them: strconv is for number conversions, strings is for text operations.

time — the famous reference layout

Go does date formatting differently from everyone else. Instead of YYYY-MM-DD, we write out a specific reference date: 2006-01-02 15:04:05.

Why those numbers? They’re a mnemonic: 1, 2, 3, 4, 5, 6, 7 → 01/02 03:04:05PM '06 -0700 (month, day, hour, minute, second, year, timezone).

now := time.Now()
formatted := now.Format("2006-01-02 15:04:05") // e.g. 2026-05-30 14:30:00
parsed, _ := time.Parse("2006-01-02", "2026-05-30")

d := 3 * time.Hour            // durations are typed
time.Sleep(2 * time.Second)   // pause
elapsed := time.Since(now)    // how long since a time

That 2006-01-02 15:04:05 layout trips everyone up the first time — interviewers love asking about it. Just memorize the reference date.

os, io, bufio — files and streams

os talks to the operating system (files, args, env vars). io defines the universal Reader/Writer interfaces. bufio adds buffering for efficient reads.

data, _ := os.ReadFile("config.txt") // read a whole file into []byte
os.WriteFile("out.txt", data, 0644)  // write a file (0644 = permissions)

arg := os.Args[1]            // command-line arguments
home := os.Getenv("HOME")    // environment variable

// read a file line by line with bufio (efficient for big files)
f, _ := os.Open("big.txt")
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
	fmt.Println(scanner.Text()) // one line at a time
}

io.Reader and io.Writer are everywhere in Go — files, network connections, HTTP bodies, and buffers all implement them, so the same code works across all of them.

sort — ordering things

sort orders slices. There are quick helpers for the common types and a generic-ish sort.Slice for custom logic.

nums := []int{3, 1, 2}
sort.Ints(nums)                  // [1 2 3]

words := []string{"c", "a", "b"}
sort.Strings(words)              // [a b c]

// custom sort with a less-function
people := []struct{ Age int }{{30}, {20}}
sort.Slice(people, func(i, j int) bool {
	return people[i].Age < people[j].Age // sort by age ascending
})

slices & maps — the modern helpers (Go 1.21+)

Go 1.21 added the slices and maps packages — generic helpers that save us from writing the same loops over and over.

import "slices"

nums := []int{3, 1, 2}
slices.Sort(nums)                  // simpler than sort.Ints
slices.Contains(nums, 2)           // true
i, found := slices.BinarySearch(nums, 2)
maxVal := slices.Max(nums)         // 3
import "maps"

m := map[string]int{"a": 1, "b": 2}
keys := maps.Keys(m)   // iterator over keys (Go 1.23+ returns an iterator)
clone := maps.Clone(m) // shallow copy of the map

Before these, we hand-wrote a loop every time we wanted to check if a slice contained a value. Now it’s one call. If an interviewer asks how you’d check membership in a slice, mention slices.Contains — it shows you know modern Go.

Why this matters in interviews

When asked “why Go for backend?”, a strong answer is the standard library. We get a production HTTP server, JSON, testing, crypto, and time handling without pulling in a single dependency. Fewer dependencies means fewer supply-chain risks and less version churn.

Interview soundbite

Go’s standard library is “batteries included” — net/http, encoding/json, testing, and crypto all ship with the language. Daily drivers are fmt (printing, %v/%+v), strings/strconv (text vs number conversions), time with its quirky 2006-01-02 15:04:05 reference layout, os/io/bufio (the universal Reader/Writer interfaces), sort, and the newer generic slices/maps packages from 1.21+. Leaning on the stdlib over third-party deps is a real selling point of the language.