Go (Golang) Standard Library: Complete Overview

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Go Standard Library: A Powerful Foundation for Any Application



The Go (Golang) standard library is not just a set of utilities. It is a carefully designed ecosystem that covers 80% of a developer's needs when creating server, network, and console applications. Unlike many languages where the standard library is just a basic minimum, in Go it includes a full-fledged HTTP server, a JSON client, powerful concurrency tools, and even a profiler. Below is a detailed breakdown of the key packages.



1. The fmt and io Packages: The Foundation of I/O

The fmt package is the first thing a beginner encounters. It provides the Printf, Sprintf, and Scanf functions for formatted output and input. But the real power lies in the io package and its Reader and Writer interfaces.

package main

import ( "fmt" "io" "strings")

func main() { // io.Reader — any data source reader := strings.NewReader("Hello, Go!") data, _ := io.ReadAll(reader) fmt.Println(string(data)) // Output: Hello, Go!}


2. The net/http Package: Creating a Web Server in 5 Lines

Go is famous for its built-in HTTP support. The net/http package allows you to run a full-fledged web server without external dependencies. It is an ideal tool for microservices and APIs.

package main

import ( "fmt" "net/http")

func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])}

func main() { http.HandleFunc("/", handler) http.ListenAndServe(":8080", nil) // Server on port 8080}


3. The encoding/json Package: Working with JSON Without Pain

Data serialization and deserialization is a common task. The encoding/json package uses struct tags for flexible field mapping. It is faster than many third-party libraries because it works at the reflection level, optimized for Go.

package main

import ( "encoding/json" "fmt")

type User struct { Name string `json:"name"` Age int `json:"age"`}

func main() { jsonStr := `{"name":"Alice","age":30}` var user User json.Unmarshal([]byte(jsonStr), &user) fmt.Printf("%+v", user) // Output: {Name:Alice Age:30}}


4. The sync Package: Tools for Concurrency

Go was created for multithreaded applications. The sync package provides Mutex, RWMutex, WaitGroup, and Once. But the main gem is sync.Map, a thread-safe map optimized for scenarios with frequent reads.

package main

import ( "fmt" "sync")

func main() { var wg sync.WaitGroup for i := 0; i < 5; i++ { wg.Add(1) go func(n int) { defer wg.Done() fmt.Println("Goroutine:", n) }(i) } wg.Wait() // Wait for all goroutines to finish}


5. The strings and strconv Packages: Working with Text

The strings package contains functions for searching, replacing, splitting, and joining strings. strconv handles converting strings to numbers and back, as well as character escaping. These packages are written in assembly and operate with maximum performance.

package main

import ( "fmt" "strings" "strconv")

func main() { // strings phrase := "hello world" fmt.Println(strings.ToUpper(phrase)) // HELLO WORLD

// strconv num, _ := strconv.Atoi("42") fmt.Println(num + 8) // 50}


6. The testing Package: Built-in Testing

Go includes a powerful framework for testing

Recommendations