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
5: Understanding GOPATH and Modules History
Wait, what was GOPATH and why do I keep seeing it in old tutorials?
If you're reading a blog post from 2017, you'll see a lot of talk about the GOPATH. Back then, Go had a very rigid opinion about where your code lived. You couldn't just create a folder on your desktop and start coding; your project had to live inside a specific directory structure, usually ~/go/src/github.com/yourname/project.
I'll be honest: it was a headache. If you wanted to use two different versions of the same library for two different projects, you were essentially out of luck. You were stuck with one global version of every dependency. It worked for small things, but for professional software engineering, it didn't scale. Thankfully, the community pushed for a better way, which led us to Go Modules.
So how do Modules actually solve this?
Modules decoupled your code from that one giant folder. Now, you can put your project anywhere—your Documents folder, a dedicated /dev partition, wherever. The "magic" happens when you run go mod init.
Let's say you're building a tool to track your coffee intake. Instead of worrying about where the folder is on your hard drive, you just do this:
mkdir coffee-tracker
cd coffee-tracker
go mod init github.com/yourname/coffee-tracker
That go mod init command creates a go.mod file. This file tells Go, "Everything in this folder is part of this specific module." Now, when you import a library, Go knows exactly which version your project needs, regardless of what other projects on your machine are doing. It's a massive quality-of-life improvement.
What are those go.mod and go.sum files actually doing?
You've probably noticed that as soon as you add an external dependency, two files appear. Think of go.mod as your manifest. It lists the module name, the version of Go you're using, and the specific versions of the libraries you've imported.
For example, if you use the popular google/uuid package to generate unique IDs for your coffee entries, your go.mod might look like this:
module github.com/yourname/coffee-tracker
go 1.21
require github.com/google/uuid v1.6.0
Then there's go.sum. Don't ever edit this file by hand. It contains cryptographic checksums of the dependencies. It's there to ensure that if you download the uuid package today, and your teammate downloads it tomorrow, you both get the exact same bytes. It prevents "dependency drift" and keeps your builds secure. I've seen plenty of developers try to delete it to "clean up" their project—don't do that. Go will just regenerate it anyway.
Do I still need to set any environment variables?
For 99% of your work today? No. You don't need to manually set GOPATH in your .zshrc or .bashrc to get things running. Go handles the module cache in a default location (usually $GOPATH/pkg/mod), but it does this behind the scenes.
You might see old guides mentioning GO111MODULE=on. That was a transition flag used years ago to force Go to ignore the old GOPATH logic. In modern Go versions, modules are the default. Just run your go mod init, write your code, and let the toolchain handle the plumbing.
📋 Practical Task
Exercise: Migrating a Legacy Directory to a Go Module
Imagine you've inherited a "legacy" project from a former teammate. The project is currently sitting in a folder that mimics the old GOPATH structure, but it lacks a go.mod file, meaning you can't easily manage dependencies or build it on a modern system.
Your Goal: Transform this legacy folder into a proper Go Module.
- Create a directory named
legacy-app. - Inside that directory, create a file named
main.gowith a simple program that imports thegithub.com/google/uuidpackage and prints a new UUID to the console. - Try to run the program using
go run main.go. You should see an error because the dependency isn't tracked. - Initialize the project as a module using
go mod init legacy-app. - Run
go mod tidyto automatically find the missinguuiddependency and update yourgo.modandgo.sumfiles. - Run
go run main.goagain to verify the program now compiles and executes correctly.
There are no comments for now.