Skip to content

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 go command (run, build, mod, fmt, version)
  • Go modules and go.mod
  • Program structure: package main, func main, imports

📖 Reading / Sources

📝 Notes

  • A Go program starts in package main's func main(). Executable packages are main; everything else is a library package.
  • A module is a collection of packages with a go.mod at its root declaring the module path and Go version. go mod init example.com/me/go-from-zero creates it.
  • go run . compiles + runs in one step (no binary left behind); go build produces a binary.
  • gofmt (via go 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

package main

import "fmt"

func main() {
    fmt.Println("Hello, Go 🐹")
}

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 init first → 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)

  1. Q: What file makes a directory a Go module, and what does it contain?
    Ago.mod — declares the module path and the Go version (and later, dependencies).
  2. Q: Difference between go run and go build?
    Ago run compiles and immediately executes without leaving a binary; go build produces 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)