Introduction to Go and the Toolchain
What Go is, why it exists, and the shape of a minimal Go program.
What you'll learn
- Explain what kind of language Go is and what it's commonly used for
- Identify the parts of a minimal Go program: package, import, func main
- Describe what `go run` and `go build` each do
Explanation
Go (often called Golang) is a statically-typed, compiled language created at Google, designed for simplicity, fast compilation, and built-in support for concurrency. It compiles to a single, standalone binary with no external runtime to install -- a major reason it's popular for backend services, command-line tools, and cloud infrastructure (Docker and Kubernetes are both written in Go).
Every Go program starts with a package declaration. An executable program's entry-point file declares package main, and Go looks for a function named main inside it to run first. Anything the program needs from outside itself -- including Go's own standard library -- comes in through an import statement.
Go ships with two everyday commands: go run file.go compiles and immediately runs a program without leaving a binary behind (convenient while developing), and go build compiles it into a standalone executable file you can distribute and run later without Go installed.
This platform can't safely compile or execute real Go code in your browser (see this course's guided-lab notice on every lesson), so instead of a live runner, each lesson gives you real Go source code and asks you to work out what it does -- exactly the skill of reading code you'll need constantly as a working Go developer.
Guided lab
Predict: A minimal Go program
Read this program and predict exactly what it prints when run with `go run main.go`.
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
fmt.Printf("2 + 2 = %d\n", 2+2)
}Stuck? Get a hint.
Common mistakes
- Forgetting that Go requires every imported package to actually be used -- an unused import is a compile error, not just a warning.
- Confusing `go run` (compile + run, no binary kept) with `go build` (compile to a binary, don't run it).
- Assuming Go needs a separate runtime installed on the machine running the compiled binary -- it doesn't; the binary is standalone.
Knowledge check
Takeaway
A Go program's entry point is `func main` inside `package main`; `go run` compiles and runs immediately, `go build` produces a standalone binary.
Summary
Go is a compiled, statically-typed language built for simplicity and concurrency, distributed as standalone binaries with no external runtime required.
References
Your notes
Notes save automatically.
Finished this lesson?
Mark it complete to track your progress and schedule a future review.
AI tutor
The optional AI tutor isn't enabled in this deployment. All lessons, exercises, quizzes, and search work fully without it.