Go build command find private gitlab repositorie

Hi. I am having a struggle using go.mod and private gitlab repository. When I try to build my project go tries to download my repo and gets error 410 Gone.


windows 10

My project structure:

private repo:



I am working in private/cmd/prj1 directory.


module gitlab.com/me/private

go 1.13.4

What I tried:

And every time the same 410 error… I am out of ideas. Maybe someone has a solution? Or maybe go does not support working in private repositories cmd folder?

1 Like

Well, I guess I fount the solution :smiley:
In cmd/prj add go.mod file and add this line:
replace gitlab.com/me/private => …/…/

Note! /path/to/repository has to have go.mod file. See documentation.

1 Like

It’s not clear what you are trying to achieve.

set GOPRIVATE=gitlab.com/me/private should be enough if you want that the packages are not downloaded from proxy.golang.org. That is the purpose of the GOPRIVATE environment variable. See go help module-private.

Are you importing packages from this private repo ?

To test your problem, I created a new project with a go.mod module with name gitlab.com/me/private.
In the project I created a package named pkg1, and a main.go file in the directory cmd/app. The main function calls a function in the package. The import path is gitlab.com/me/private/pkg1.

I build it with the command GOPRIVATE="gitlab.com/me/private" go build ./cmd/app.

It compiles without a peep and the executable named app stored next to the go.mod file runs as expected. As you see the go build doesn’t need to access the gitlab repository to build the project. So I don’t understand what is wrong and why you would need this replace instruction. I don’t need it.

1 Like

I was very happy finally to find solution, but after your comment I checked go.mod file and found out, that when defining module name, I accidentally make mistake by swapping two letters together… Yep, now it works like defined in documentation :slight_smile: Thanks for your help @Christophe_Meessen.

1 Like

Good to see that things are now working as expected.
Please mark the question as answered. Click the check mark box in grey.

1 Like

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