Search code examples
gomodulegitlab

make an internal go module available to more projects


In one of my projects I've used an internal module:

package main

import (
    "gitlab.example.com/team/project/internal/exitcodes"
)

That worked fine.

Now I need that module in another project as well and I fail to achieve that.

First I created a new repository where I put the module: gitlab.example.com/team/gocommon

and changed the import accordingly to "gitlab.example.com/team/gocommon/exitcodes".

Then I created an accesstoken and put it into ~/.netrc

machine gitlab.example.com
    login gogettoken
    password DBJMsPsGrFAiMq2MDRRT

But the project fails to build with:

gitlab.example.com/team/gocommon/exitcodes: gitlab.example.com/team/[email protected]: verifying module: gitlab.example.com/team/[email protected]: reading https://sum.golang.org/lookup/gitlab.example.com/team/[email protected]: 404 Not Found
server response:
not found: gitlab.example.com/team/[email protected]: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/5c5d3cb0b00b8d48278234b7d0c82797966117d16c9fedbd2cf87e471d549e5b: exit status 128:
        fatal: could not read Username for 'https://gitlab.example.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

I already checked the mentioned golang.org link, but it didn't help me ot find a solution.


Solution

  • Looks like you have problems with ssh git and https git. Is somebody in your company already done it? May be there are some security issue with infrastructure configuration.

    Check few things without order, just any of this list might help you to understand where is the problem:

    • Try to git clone your new repo, is there any issues? is it git url or https?
    • You have access to that repo (looks like it's yours so i think answer is yes)
    • run go mod tidy
    • try to add .netrc to project folder. Some systems that I saw don't work for some reason from ~/.netrc
    • put content of .netrc in one line
    • try go get <package> by hand
    • do you use password in .netrc or token from gitlab? I think it should be token.
    • and of course your module need a tag on it or you can use commit hash
    • set GOPRIVATE if you need more that one use comma as a separator