How do you use replace
in go.mod
when you want to replace a pkg that an imported pkg uses?
The Problem
Project uses Lib
Lib uses SubLib
Project
Lib
SubLib
You want to replace SubLib with a local version that you're working on to see the result in Project.
The Answer
Open go.mod
in Project to use the replace
directive.
// go.mod
require(
github.com/example/lib
// `lib` imports github.com/sublib/sublib
)
replace github.com/sublib/sublib => /local/dir/sublib
Profit!
May my hours of suffering help another.
Top comments (0)