Using a local copy of a module
Sometimes, you will work on multiple modules, or you download a module from a repository, make some changes to it, and then want to use the changed version instead of the version available on the repository.
How to do it...
Use the replace
directive in go.mod
to point to the local directory containing a module.
Let’s return to our example – suppose you want to make some changes to the sqlite
package:
- Clone it:
$ ls webform $ git clone [email protected]:cznic/sqlite.git $ ls sqlite webform
- Modify the
go.mod
file under your project to point to the local copy of the module.go.mod
becomes the following:module github.com/PacktPublishing/Go-Recipes-for-Developers/chapter1/webform go 1.22.1 replace modernc.org/sqlite => ../sqlite require ( github.com/gorilla/mux v1.8.1 modernc.org/sqlite v1.27.0 ) ...
- You can now make changes in the
sqlite
module on your system, and those changes will be built into your application.