Import package locally during development only


A question about the dev process, when working with dependencies.



In the module ‘worker’ I import ‘data’. I use ‘go get -u’, so data is referenced in worker/mod.go with a version.

What is the Go approach to avoid the round trip of commit/push/go get, and instead reference ‘data’ via the local filesystem during development? So as I save changes (pre commit) my ‘worker’ module picks up the changes.


You can use the replace clause inside worker/go.mod to define local import pathing. Example:

replace ( => ./tmp/local/data

However, you do need to keep local “data” path available for import and must have a go.mod in it. You then need to clone into the relative path ./tmp/local/data.

The local import pathing can also accept absolute path.

Normally I would remove the clause before I commit a release. If you decide to keep it. You must ensure the distribution is capable to getting its own “data” package in the specified path.

1 Like

excellent, thanks.

Yes, I can strip out the replace statement during the CI pipeline. If I use single statements I can grep them out, during deploy/test.

require v1.1.1
replace => ../data // not-prod


Glad to hear =)

Please make the appropriate post as “solved” for future search reference and to save other helpers in the forum from doing double efforts.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.