Go is a compiled language designed for understandable programs, fast builds, and practical concurrency. This tutorial gives you the mental model and sequence needed to start building backend services.
Reviewer’s note: This is the site’s foundational Go path for beginners. The examples establish the toolchain, language basics, error handling, concurrency, testing, and HTTP foundations that the deeper tutorials build on.
Install Go and verify the toolchain
Install Go from the official site, then check the version:
go version
Create a module and first program:
mkdir hello-go
cd hello-go
go mod init example.com/hello-go
package main
import "fmt"
func main() {
fmt.Println("Hello, Go")
}
Run it with go run .; format it with go fmt ./...; test it with go test ./....
Variables, control flow, and functions
Go infers local variable types with := while package-level declarations use var. The zero value makes every declared variable usable.
func priceWithTax(price float64, rate float64) float64 {
return price * (1 + rate)
}
total := priceWithTax(20, 0.12)
if total > 20 {
fmt.Println("tax applied")
}
Go has one loop keyword, for, which covers counting, conditions, and ranges. Prefer small functions with explicit inputs and outputs.
Model data with structs and methods
type User struct {
ID int
Name string
}
func (u User) Greeting() string {
return "Hello, " + u.Name
}
Methods attach behavior to a type. Use pointer receivers when the method mutates the value or copying it would be undesirable.
Handle errors explicitly
user, err := loadUser(id)
if err != nil {
return fmt.Errorf("load user %d: %w", id, err)
}
Errors are values. Return them, wrap them with context, and inspect known causes with errors.Is or errors.As. Reserve panics for unrecoverable programming errors.
Learn interfaces from the consumer
Interfaces describe behavior. Define small interfaces near the code that consumes them rather than creating large abstractions in advance.
type UserStore interface {
Find(context.Context, int) (User, error)
}
Any type with that method satisfies the interface automatically.
Add concurrency deliberately
Goroutines run functions concurrently; channels communicate values; mutexes protect shared state. Concurrency is useful when work can overlap, not as a default replacement for straightforward sequential code.
Continue with goroutines, channels, WaitGroup, and mutexes.
Build and test an HTTP handler
func health(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
io.WriteString(w, `{"ok":true}`)
}
Register the handler with a ServeMux, then test it using httptest. The HTTP server tutorial and REST API tutorial develop this into a complete service.
A practical learning order
- Write small command-line programs until functions, slices, maps, and structs feel normal.
- Learn error handling and package design.
- Write table-driven tests.
- Learn goroutines, channels, cancellation, and race detection.
- Build an HTTP service using the standard library.
- Add persistence, observability, and deployment only after the core service is correct.
The fastest route is repeated practice: read one concept, write a small program, test it, and use it in a larger project.