Go
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Functions and Methods
-
Section 4: Concurrency
-
Section 5: Packages and Tooling
-
Section 6: More Standard Library
-
Section 7: Building Services
-
Section 8: Advanced Go
-
Section 9: Go in the Cloud-Native Ecosystem
-
Section 10: Data Structures and Algorithms in Go
-
Section 11: Testing and Deployment
-
Section 12: Practical Projects
-
Section 13: More Standard Library Practice
-
Section 14: More Practice Projects
-
Section 15: Design Patterns in Go
-
Section 16: Interview Practice
-
Section 17: Package fmt In Depth
-
Section 18: Package strings and strconv
-
Section 19: Package os and io
-
Section 20: Package time
-
Section 21: Package sort and container
-
Section 22: Package encoding
-
Section 23: Package net/http In Depth
-
Section 24: Package context
-
Section 25: Package regexp and bytes
-
Section 26: Package errors In Depth
-
Section 27: Package crypto and hash
-
Section 28: Package flag and log
-
Section 29: Package sync In Depth
-
Section 30: More Practice Exercises
-
Section 31: Go Modules and Workspaces In Depth
-
Section 32: Generics Deep Dive (Go 1.18+)
-
Section 33: Testing Package In Depth
-
Section 34: More Interview and Whiteboard Practice
-
Section 35: Package math and unicode
-
Section 36: Package path and filepath
-
Section 37: Package database/sql
-
Section 38: Package text/template and html/template
-
Section 39: Package archive and compress
-
Section 40: Lower-Level net Package
-
Section 41: Package runtime and reflect
-
Section 42: Package embed and io/fs
-
Section 43: Go Assembly and CGO Basics
-
Section 44: Building CLIs and TUIs
-
Section 45: Go Performance Tuning
-
Section 46: More Real-World Projects
-
Section 47: Go in Production
-
Section 48: Go Design Patterns
-
Section 49: Go Interfaces Deep Dive
-
Section 50: Final Practice and Review
1: Installing Go and Setting Up Modules
First, get Go on your machine. If you're on a Mac, brew install go is the fastest path; otherwise, grab the installer from the official site. Once you've verified it's working with a quick go version check in your terminal, you'll likely be tempted to just create a folder, throw a main.go file in there, and start coding. For a single-file script, that works fine. But the moment you want to build something real—something that uses external libraries or is split across multiple files—that "just start coding" approach will bite you.
The "just let it run" trap
I see a lot of beginners start by creating a directory and immediately writing code. They might try to import a third-party package—say, a library for coloring terminal output like github.com/fatih/color—and then run go run main.go. At first, Go might actually be smart enough to fetch the dependency, but you'll quickly run into a wall. Without a module definition, Go doesn't actually know the identity of your project. It doesn't know if your code is a standalone tool or part of a larger library.
The real pain happens when you try to organize your code into sub-packages. If you create a folder called /auth and try to import it into your main.go, the compiler will scream at you. It can't resolve the path because there's no "root" to the project. You're essentially telling Go, "Here is a file," but you aren't telling it, "Here is a project." This is the old way of doing things (the pre-2018 GOPATH era), and it's a headache you don't want.
Defining your project boundary with modules
The professional way to handle this is to initialize a module immediately. Before you write a single line of Go, you run go mod init [module-name]. I usually name the module after the repository where it will live, like go mod init github.com/yourname/github-fetcher. This creates a go.mod file, which is essentially the manifest for your project.
Why bother with this extra step? Because the go.mod file transforms your folder from a random collection of files into a versioned unit. When you import that color library now, Go doesn't just download it; it records the exact version of that library in your go.mod file. If you hand your project to me six months from now, I can run it and be guaranteed that I'm using the exact same dependency versions you were, rather than whatever the latest (and potentially breaking) version is at the time.
# The right way to start a project
mkdir github-fetcher
cd github-fetcher
go mod init github.com/username/github-fetcher
touch main.go
Once that's done, you can use go mod tidy. This is a command I use constantly. It cleans up your go.mod file, removing dependencies you've stopped using and adding any that you've imported in your code but haven't formally added to the module yet. It keeps your dependency graph lean and prevents your project from becoming a bloated mess of unused libraries.
📋 Practical Task
Initialize a GitHub User Tool and Resolve Dependencies
Your task is to set up the foundation for a tool that fetches GitHub profile data. Instead of just writing a file, you need to establish a proper module structure that can handle external dependencies.
- Create a new directory named
github-profile-tool. - Initialize a Go module named
github.com/learning-go/profile-tool. - Create a
main.gofile and add a simplepackage mainandfunc main() {}block. - Add an import for the popular coloring library:
"github.com/fatih/color". - Inside your
mainfunction, use the library to print "Project Initialized" in green (Check the library's documentation or usecolor.Green("Project Initialized")). - Run
go mod tidyin your terminal to synchronize your dependencies. - Verify that your
go.modandgo.sumfiles have been created and updated with thefatih/colordependency.
There are no comments for now.