Advise on working with local modules

82 views
Skip to first unread message

Manlio Perillo

unread,
Jan 19, 2020, 1:01:21 PM1/19/20
to golang-nuts
I have several personal projects in Go, and some of these projects depends on other personal projects.
Since they are still in development, they are not available on a public repository.

I have found a solution that seems to work, but I would like some advise.
My projects are all in GOPATH (~/src/go/src);


  1. Use URL rewriting in .gitconfig, e.g.

     [url "ssh://manlio@localhost:/home/manlio/src/go/src/github.com/perillo/"]
         insteadOf = https://github.com/perillo/

  2. Set the `GONOSUMDB` environment variable in the shell, e.g.

     export GONOSUMDB="github.com/perillo/*"

  3. Optionally, to fill the cache when releasing a new version of a local
     module:

     go mod download $(go list -m)@latest


The third point is unnecessary.  I added it in an effort to avoid to add the URL rewriting permanently in .gitconfig.

What are the possible problems with this solution?


Thanks
Manlio Perillo

Tamás Gulácsi

unread,
Jan 19, 2020, 5:47:30 PM1/19/20
to golang-nuts
Why not just the replace directive in go.mod?

Manlio Perillo

unread,
Jan 20, 2020, 2:51:09 AM1/20/20
to golang-nuts
On Sunday, January 19, 2020 at 11:47:30 PM UTC+1, Tamás Gulácsi wrote:
Why not just the replace directive in go.mod?

With the replace directive to a local module, the version is ignored and the go tool always use the latest commit.


Manlio Perillo 

Paul Jolly

unread,
Jan 20, 2020, 5:43:49 AM1/20/20
to Manlio Perillo, golang-nuts
>> Why not just the replace directive in go.mod?
>
> With the replace directive to a local module, the version is ignored and the go tool always use the latest commit.

How are you envisaging that local modules be addressed by commit,
given the target is a directory (where by definition only a single
commit can be "current")?

Tamás Gulácsi

unread,
Jan 20, 2020, 6:26:38 AM1/20/20
to golang-nuts
Why do you want to pin to a commit when everything is in flux - develop locally?

The replace directive uses the current code when you declare it as a local path, not the version specified in the "require" section!

Manlio Perillo

unread,
Jan 20, 2020, 9:01:53 AM1/20/20
to golang-nuts

On Monday, January 20, 2020 at 12:26:38 PM UTC+1, Tamás Gulácsi wrote:
Why do you want to pin to a commit when everything is in flux - develop locally?

Because to decide when the API is good for publication I want to use it in 1+ projects.
Since the local development period may be long, I want to be able to pin a version, to avoid breaking old projects.
 

The replace directive uses the current code when you declare it as a local path, not the version specified in the "require" section!


I believe I wrote exactly the same thing.

Thanks
Manlio Perllo
Reply all
Reply to author
Forward
0 new messages