DEV Community

William Antonelli
William Antonelli

Posted on

go.mod replace: fallthrough

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Profit!

May my hours of suffering help another.

Top comments (0)