Michael Lee Squires
Michael Lee Squires

Reputation: 81

Is there a way to override a package?

I have import statements in my code that look like this:

import "github.com/A/package"

It turns out that - temporarily - I need to use github.com/B/package.

Rather than modify the source, and re-modify it later, is there a way to specify an override?

Upvotes: 1

Views: 3034

Answers (1)

Since Go1.11, modules allow the use of the replace directive in the go.mod file of the project. It allows to override an expressed dependency by another module.

Online reference is https://go.dev/wiki/Modules#when-should-i-use-the-replace-directive

Upvotes: 1

Related Questions