Learn Go | Tutorial 1 (The Handshake): Your First Go Program
- Part 1: Learn Go | Tutorial 1 (The Handshake): Your First Go Program
- Part 2: Learn Go | Tutorial 2: Storing a Thought (Variables)
- Part 3: Learn Go | Tutorial 3: The Grocery List Problem
- Part 4: Learn Go | Tutorial 4: Listening to the User
- Part 5: Learn Go | Tutorial 5: Making Choices (The Command Loop)
- Part 6: Learn Go | Tutorial 6: The Memory Loss Issue (File Persistence)
Objective: Get the Go tools installed, set up your project workspace, and verify that your code can talk to the terminal.
Step 1: The Setup π
Before writing logic, we need the “engine”.
- Install Go: Download the installer for your OS from go.dev .
- Verify: Open your terminal (Command Prompt, PowerShell, or Terminal) and type:If you see something like
go versiongo version go1.25.1..., you are ready.
Step 2: The Workspace π
Go requires a specific project structure to manage dependencies. We call this a “Module”.
- Create a folder for your project anywhere you like:
mkdir go-getter cd go-getter - Initialize the module. This tells Go, “This directory contains a valid Go project”.Note:
go mod init example.com/go-getterexample.com/go-getteris a unique ID for your project. You can change it to your GitHub URL later, but this works fine for now.
You will see a new file called go.mod. Leave it alone for now; it’s the project’s ID card.
Step 3: The Code π
We need an entry point. In Go, every executable program starts in a package called main.
- Create a file named
main.goinside your folder. - Open it in any text editor (VS Code, Notepad++, etc.) and type this exactly:
package main
import "fmt"
func main() {
fmt.Println("Go-Getter: System Online")
}
Make sure to save changes by clicking CTRL+S (or CMD+S).
Step 4: Run It π
Back in your terminal, inside the go-getter folder, run:
go run main.go
Output:
Go-Getter: System Online
Step 5: Deconstruct (The “Why”) π
You just wrote code to solve the need: “Verify the system works”. Here is what you used:
package main: This line is mandatory for any code you want to run. If you named itpackage tool, Go would treat it as a library helper, not a runnable program.import "fmt": Go is minimal. It doesn’t even know how to print text by default. We have to import thefmt(Format) package from the standard library to format text for the screen.func main() { ... }: This is the ignition switch. When you run the program, Go looks for a function specifically namedmainand executes it first.fmt.Println: “Print Line”. It sends text to the standard output (your terminal) and hits “Enter” at the end (new line).
Challenge for Tutorial 2:
Right now, the message “Go-Getter: System Online” is hardcoded. If we want to change the app name, we have to find it inside the print statement. In the next tutorial, we will solve this by introducing Variables.
I hope you enjoyed reading this post as much as I enjoyed writing it. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , and GitHub .
- Part 1: Learn Go | Tutorial 1 (The Handshake): Your First Go Program
- Part 2: Learn Go | Tutorial 2: Storing a Thought (Variables)
- Part 3: Learn Go | Tutorial 3: The Grocery List Problem
- Part 4: Learn Go | Tutorial 4: Listening to the User
- Part 5: Learn Go | Tutorial 5: Making Choices (The Command Loop)
- Part 6: Learn Go | Tutorial 6: The Memory Loss Issue (File Persistence)