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 git@gitlab.com:cznic/sqlite.git $ ls   sqlite   webform
- Modify the
go.modfile under your project to point to the local copy of the module.go.modbecomes 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
sqlitemodule on your system, and those changes will be built into your application.