Import package locally during development only

Hi,

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

example:

src/github.com/thisdougb/worker/
src/github.com/thisdougb/data/

In the module ‘worker’ I import ‘data’. I use ‘go get -u github.com/thisdougb/data/’, 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.

thanks,

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

replace (
     github.com/thisdougb/data => ./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 github.com/thisdougb/data 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 github.com/thisdougb/data v1.1.1
replace github.com/thisdougb/data => ../data // not-prod

cheers,

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.