DEV Community

William Antonelli
William Antonelli

Posted on

3 1

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →