← rhash

Go — Lesson 1: Your First Go Run

Learning track

New to programming? This lesson was written for you — it assumes nothing, explains every new word in plain language, and never skips a step. The lab is a practice terminal that behaves like the real Go tools (go run, go build, gofmt, go vet), so you can learn by doing. Nothing to install, no account — and when you're ready for the real thing, Go itself is a free download from go.dev.

Lesson 1 · Never written code before? You are in the right place

Your First Day with Go

Welcome. This track teaches you Go — a popular programming language — by building one real project together, step by step: linkstash, a small tool that saves links (like browser bookmarks) and finds them again when you need them. Today you will set the project up and run it for the first time. Later lessons grow it into a program that answers web requests, does several jobs at once, and remembers your links between runs — and the track ends with you improving a real open-source project that strangers actually use.

How this lesson works: read this page from top to bottom (about 15 minutes), then open the Lab tab and follow six small steps, typing real commands into a practice terminal. Nothing to install, no account, and nothing you can break. Every new word is explained in plain language the first time it appears — and each step builds on the one before it, never skipping ahead.

Brand new to this? Three ideas first

If you have never programmed, start with these three ideas. Everything else in the lesson is built on them.

1 · A program is a recipeA program is a list of instructions that a computer follows exactly, in order. The instructions are written as text — that text is called code, and the file holding it is a source file.
2 · The terminal takes typed ordersBesides clicking buttons, you can type commands into a window called a terminal and press Enter. The computer carries out the command and prints the result underneath. The lab at the end of this lesson is a safe practice terminal.
3 · Compiling is translatingA computer cannot run your code text directly. A tool called a compiler translates it into a file the computer can run. Translating is called compiling, and the translated file is called a binary.

That is genuinely enough to begin. From here, each idea gets the same treatment: the plain explanation first, the official name second.

The pain Go was born from

In 2007, the engineers at Google were building enormous programs that run behind the scenes on servers — the computers that power websites and apps. Their tools fought them: translating their code into runnable form (compiling it — idea 3 above) could take the better part of an hour, the language they used had so many features that nobody could hold all of it in their head, and keeping track of which extra pieces of code a program depended on felt like defusing a bomb. Computers had also become good at doing many things at the same time — called concurrency — but their language made that painful, so people mostly avoided it.

Picture a workshop where every job starts with sharpening the tools for an hour. The craftspeople are skilled — the workshop itself is the bottleneck. Eventually someone asks: what if we designed the workshop around the work?

That question produced Go (often nicknamed Golang, after its old website name). Go is a programming language created at Google by Robert Griesemer, Rob Pike, and Ken Thompson. Its founding bet: a language meant for big teams and big programs should itself be small — few features to learn, fast compiling, and doing-many-things-at-once built in from the start instead of added later. Everything in this lesson is that bet made visible.

“It works on my machine” is not enough

Here is a classic surprise. Your program works perfectly on your computer. You send it to another computer — say, the server that will run it for real — and it refuses to start. The reason: many programs secretly need helper software installed first (a runtime), at exactly the right version, plus extra ready-made pieces called libraries. Miss one piece and nothing runs. Sending a program to the computer that will run it for real is called deploying it — and this is why deploying has a reputation for pain.

Think of shipping furniture two ways. Flat-pack means the receiver needs the right tools, the right screws, and patience. Go ships the finished piece: one sealed box, nothing to assemble at the other end.

go build — the command that compiles your program — packs your code, plus the few helper pieces of Go it needs, into one single file (programmers call such a self-contained file a static binary). Nothing else to install on the other computer, no pieces to hunt down. Copy one file, run it. In the lab you will make exactly such a file and run it yourself.

The endless argument about how code should look

Code has a look as well as a meaning: how far each line is indented, where the curly braces { } sit, how lists are ordered. Put five programmers on one project and you get five different looks — and endless arguments about which look is “right”. Those arguments burn time that should go to whether the code actually works, and they are never truly settled.

Imagine a newsroom with exactly one stylebook, enforced by a tireless robot editor. Writers stop debating commas and argue about the story instead. Nobody loves every rule; everybody loves that the argument is over.

In Go, that robot is gofmt. There is exactly one official format, gofmt applies it automatically, and that is why Go code everywhere looks the same. In Go culture this is not a suggestion — it is closer to a law. Handing in unformatted code is like handing in homework covered in coffee stains: people judge the mess before they read a word. So from today: run gofmt on everything, always. Its partner check, go vet, joins in during the lab.

Every project needs an ID card

A Go project is just a folder holding code files. But Go needs to know the project's name, and exactly where the project starts and ends. Early Go handled this badly: every project had to live inside one rigid shared folder, and moving a project broke it. Real projects needed a cleaner answer.

Think of the label on a folder in a filing cabinet. One small label that says what the folder is called and what belongs inside it — so anyone (or any tool) picking it up immediately knows what they are holding.

Go's label is a small file named go.mod, and a project that has one is called a module. You create it once by typing go mod init linkstash in the terminal, and from then on Go knows the project's name and boundaries no matter where the folder lives. The lab's second task is exactly this command — you will watch go.mod appear.

Mental model #1: your program ships with a manager

Here is the pain behind Go’s most famous feature. When a program does several things at once, the computer gives it workers called threads. Threads are expensive workers: each one reserves a big chunk of memory and is managed by the computer's operating system. A busy program — say, one answering ten thousand visitors at once — cannot afford ten thousand of these heavy workers, so in other languages programmers perform complicated tricks to share a few threads between many jobs.

Picture an airport with a handful of runways and thousands of planes. The planes don’t each need a runway parked under them all day — a good tower rotates them through. Go’s runtime is that tower: a few OS threads (runways) multiplexed across many lightweight goroutines (planes), each with a tiny stack that grows only when needed.

The tower in that picture is real: it is called the goroutine scheduler, and it comes built into every Go program as part of the runtime — the helper machinery packed inside your compiled file. The lightweight planes are called goroutines. Lesson 5 puts them to work; today, just plant the picture: a Go program is never just your code — it is your code plus a small, smart manager that makes doing many things at once cheap. Every later lesson hangs on that sentence.

Errors that whisper are worse than errors that speak

In many languages, something can fail deep inside a program and you only find out when the error lands in a catch block far away — or you never find out at all. The failure path is invisible in the code you’re reading, which is exactly where you needed to see it.

Think of a delivery driver who hands you the parcel and a condition report together. “Here’s your package — and the corner is dented, check it now.” Nothing is hidden; you decide on the spot what the damage means.

First, a word: a function is a named chunk of code that does one job and can hand back results — like a vending machine: you call it, it hands something back. Go functions can hand back more than one value at once, so the convention is: the results first, and an error value last. If nothing went wrong, that error is nil — a special value meaning “empty, nothing there”. The pattern you will write thousands of times looks like this:

text, err := banner()
if err != nil {
    // handle it — right here, where it happened
}
fmt.Println(text)

In plain English: “Ask banner() for the greeting. It hands back two things — the text, and an error (nicknamed err). If the error is not nil — something did go wrong — deal with it right here, where it happened. Otherwise, print the text.”

Nothing is hidden and nothing jumps away. The error is a plain value you must consciously deal with, and if err != nil is the most recognizable sentence in Go. In the lab's final task you will rearrange linkstash's main function to use a banner() function with exactly this shape — the first habit of real Go, practiced on day one.

The standard library is the textbook

Go arrives with a big toolbox of ready-made code called the standard library — printing text, reading files, talking to the internet, and hundreds of other everyday jobs are already written for you by the Go team. Even better, the instruction booklet for every tool is one command away, even with no internet: go doc fmt.Println shows exactly what the printing function you will use today does. Try it in the lab terminal any time.

Apprentice chefs learn by reading the master’s recipe cards, not just cookbooks about cooking. In this track, when a lesson leans on a standard-library package, we read its real docs with go doc — try it in the lab terminal any time.

Your commands, on one screen

Almost everything you do in Go goes through one program — go — plus its formatting partner gofmt. (Together they are called the toolchain: the set of tools that ships with the language.) You type these commands into the terminal. Learn the rhythm now; every lesson reuses it.

go versionCheck that Go is installed and see its version number. The first thing to try when anything feels off.
go mod initCreate the project's ID card — the go.mod file that names the module.
go run .Compile and run in one step. Your inner loop while developing.
gofmt -wRewrite files in the one official format. Non-negotiable, always.
go vet ./...A proofreader for your code — flags mistakes that are legal but almost certainly wrong.
go buildCompile everything into the single file you can copy anywhere and run.
go docRead the standard library’s own documentation, offline.
go testComing in Lesson 7 with table-driven tests — listed now so the rhythm is complete.

Set up the project. Run it. Format it. Check it. Build the file. Keep that sentence in mind — you will do every one of those steps yourself in the lab.

Where this track goes

  1. 1Your First Go Run — toolchain, modules, gofmt/vet law, errors as values. You are here.
  2. 2Values, Structs & Honest Errors — linkstash learns to store real links, and to report problems honestly when something goes wrong.
  3. 3Interfaces, Satisfied Implicitly — the mental model behind Go’s quiet superpower.
  4. 4linkstash Becomes an HTTP API — linkstash starts answering web requests — the behind-the-scenes half of every website.
  5. 5Goroutines & Channels — the scheduler model, put to work checking links in parallel.
  6. 6Context, select & the Race Detector — stopping work cleanly when it is no longer needed, and automatically catching mix-ups when two jobs touch the same thing at once.
  7. 7Persistence & Table-Driven Tests — linkstash survives a restart, proven by real tests.
  8. 8The Contribution Milestone — a real issue, a real codebase, a fix with tests, a pull request. The finish line is a maintainer’s review, not a certificate.