Day 001 — Toolchain & First Program¶
Month 1 · Week 1 · Day 002 ➡ · Journal index
⭐ This is a worked example showing how to fill a day note. Delete it or keep it as a reference.
🎯 Learning Objective¶
Install the Go toolchain, understand modules, and build & run my first program.
📚 Topics¶
- The
gocommand (run,build,mod,fmt,version) - Go modules and
go.mod - Program structure:
package main,func main, imports
📖 Reading / Sources¶
- How to Write Go Code
- A Tour of Go — Basics
- Learning Go ch.1
📝 Notes¶
- A Go program starts in
package main'sfunc main(). Executable packages aremain; everything else is a library package. - A module is a collection of packages with a
go.modat its root declaring the module path and Go version.go mod init example.com/me/go-from-zerocreates it. go run .compiles + runs in one step (no binary left behind);go buildproduces a binary.gofmt(viago fmt) is non-negotiable — formatting isn't a debate in Go. Editors run it on save.- Imports must all be used or the build fails — a deliberate language choice. Related: [[zero-values]].
💻 Code Examples¶
Full code:
examples/hello/main.go· Run:go run ./examples/hello
🏋️ Exercises / Practice¶
| Exercise | Status | Link |
|---|---|---|
Print name + Go version (runtime.Version()) |
✅ | examples/hello |
| Tour of Go: Packages, Imports, Exported names | ✅ | go.dev/tour |
🐛 Mistakes Made¶
- Forgot to run
go mod initfirst →go: cannot find main module. Fix: always init the module before building. (Logged in FAQ.) - Left an unused
import "os"→ build error"os" imported and not used. Removed it.
❓ Open Questions¶
- When do I split code into multiple packages vs keep it flat? (Answer coming Week 1, Day 006.)
🧠 Active Recall (answer without looking)¶
- Q: What file makes a directory a Go module, and what does it contain?
A
go.mod— declares the module path and the Go version (and later, dependencies). - Q: Difference between
go runandgo build?A
go runcompiles and immediately executes without leaving a binary;go buildproduces a compiled binary you run yourself.
🪶 Feynman Reflection (explain it simply)¶
Go code lives in modules (a project) made of packages (folders of related code). The computer starts your program at main() inside the special main package. You point the go tool at your code and it compiles and runs it — and it insists everything be tidy (formatted, no unused imports).
🕳️ Knowledge Gaps¶
- Cross-compilation (
GOOS/GOARCH) — note for Month 2 tooling week.
✅ Summary¶
I can initialize a Go module, write a main package, and build/run/format it with the go toolchain. Environment is set up for the next 179 days.
⏭️ Next Steps / Prep for Tomorrow¶
- Day 002: variables, constants, and
iota. Skim Learning Go ch.2.
| Time spent | Difficulty | Confidence |
|---|---|---|
| 90 min | 🟦⬜⬜⬜⬜ | 🟦🟦🟦⬜⬜ |
Suggested commit: chore(repo): set up Go toolchain and first program (day 001)