Module 4: The Go CLI (The Swiss Army Knife)
📚 Module 4: The Go CLI
Course ID: GO-104
Subject: The Swiss Army Knife
One of the best things about Go is its Toolbox. You don’t need a hundred different plugins; the Go team gives you everything you need in one command: go.
🏗️ Step 1: go run vs go build
🧩 The Analogy: The Microwave vs. The Factory
go run(The Microwave): It cooks your code instantly so you can taste it (test it) quickly. It doesn’t save anything.go build(The Factory): It produces a final, wrapped Binary (Module 1) that you can sell or ship.
🏗️ Step 2: go fmt (The “Iron”)
In many languages, developers argue about where the { goes or how many spaces to use. Go solves this with one command.
🧩 The Analogy: The Professional Uniform
- You might arrive at work with a wrinkled shirt.
- You run
go fmt, and it Irons your code perfectly. - Every single Go developer in the world uses the exact same style. There is NO argument.
🏗️ Step 3: go mod (The “Parts List”)
How do you keep track of the tools other people built? You use Go Modules.
🧩 The Analogy: The Instruction Manual
go mod init: Creates the manual for your project.go.mod: The file that lists every single tool (Library) you downloaded from the internet.
🥅 Module 4 Review
- go run: Quickly testing your code.
- go build: Creating the final product.
- go fmt: Automatically cleaning and styling your code.
- go mod: Managing dependencies.
:::tip Slow Learner Note You will use go run main.go 99% of the time while you are learning. Don’t worry about the others until you are ready to ship your app! :::