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
170: Replace Directives for Local Development
I've seen this happen more times than I can count: a developer is working on a shared library and a main application simultaneously. They hit a bug in the library, fix it locally, and then add a replace directive to the application's go.mod file to point to their local folder. Everything works perfectly on their machine. Then, they commit that go.mod file and push it to the main branch. Five minutes later, the CI pipeline explodes, and every other engineer on the team is staring at a "directory not found" error.
The "Just Commit the Relative Path" Trap
The misconception is thinking that a replace directive is a way to "link" two projects permanently. It isn't. When you write something like replace github.com/myorg/logger => ../logger, you aren't telling Go how the project is structured in the cloud; you are telling the Go toolchain to ignore the remote version and look at a specific folder on your hard drive.
Let's look at a concrete example. Suppose you have a project structure like this:
/home/dev/projects/
├── auth-service/ (The app)
└── common-lib/ (The shared library)
In auth-service/go.mod, you add:
module github.com/myorg/auth-service
go 1.21
require github.com/myorg/common-lib v1.0.0
replace github.com/myorg/common-lib => ../common-lib
This works great while you're coding. You change a function in common-lib, and auth-service sees it immediately. But the moment you push this to GitHub, the Go compiler on the build server looks for ../common-lib relative to the build directory. Since the build server only cloned the auth-service repo, that folder doesn't exist. The build fails. I've had to spend a few too many Friday afternoons scrubbing these directives out of version control.
Bridging Local Modules Without Breaking CI
The replace directive is a powerful tool for iteration, not for distribution. The correct workflow is to use it as a temporary bridge. You use it to verify that your library changes actually fix the bug in the application before you ever publish the library.
Here is the professional loop for handling this:
- Local Iteration: Add the
replacedirective togo.mod. This allows you to skip the "push-tag-update" cycle every time you fix a typo. - Verification: Run your tests in the application to ensure the local library changes work.
- Release: Commit and push the changes to the
common-librepository. Create a new semantic version tag (e.g.,v1.0.1). - Integration: Remove the
replacedirective fromauth-service/go.modand rungo get github.com/myorg/common-lib@v1.0.1.
If you find yourself doing this constantly across five or six different modules, you might want to look into Go Workspaces (go.work), but for a quick fix between a library and an app, the replace directive is the fastest path—provided you treat it like a local configuration, not a project setting. Pro tip: if you're using Git, you can actually add go.mod to your .git/info/exclude file (not the tracked .gitignore) if you want to make sure you don't accidentally stage those local changes, though usually, a quick git diff before committing is enough to catch it.
📋 Practical Task
Decoupling the Payment Gateway Library
You have been handed a project called payment-processor that is currently broken in the CI pipeline. The previous developer left a local replace directive in the go.mod file that points to a directory that doesn't exist on any other machine.
Your Goal: Clean up the module dependencies so the project can be built from the remote source again.
- Open the
payment-processor/go.modfile. - Locate the line:
replace github.com/myorg/payment-sdk => ../payment-sdk. - Remove this directive entirely.
- Run
go mod tidyto ensure thego.sumfile is cleaned up and the project is pointing to the actual remote version ofpayment-sdk. - Verify the project still compiles by running
go build ./....
There are no comments for now.