Using go get to retrieve modules / packages from a private server

Go recognizes some public servers like and I’m trying to use go get with a private server. I can clone my repo with git:

git clone

I’ve gotten “go get” to work with this command:

go get

but the command then fails with

package no Go files in /home/dean/src/golang/go3p/src/

What “go get” is doing is downloading the whole path from the server, including the .git/ directory.
This also kills the possibility of keeping a git module on a private server.

I haven’t found any documentation on using a private server. The “go get” command seems to only recognize certain public servers.

Does anyone know how to use the go tool chain with packages or modules stored on a private server?

At my working place we are successfully using a self hosted gitlab instance, with public and private repositories.

Though go get will use HTTPS transfer only to clone. you need to add “rewrites” to git to enable SSH transfer.

THe following snippet will rewrite HTTPS access to with SSH access:

[url ""]
        insteadOf =

This of course assumes, that you have set up your keys correctly in SSH :smiley:

I hope this answeres your question, as I dont know what problem you are describing otherwise…

PS: Do you actually have .go files in the package?

PPS: I probably wouldn’t expose the full path to the repository in the package name, but expose it with a shorter path.

Can you give an example of an import and a go get statement that work with your private repo?

I have .go files under in the src/ directory like normal. The go get command pulls down the whole directory structure under the first entry in my GOPATH (including srv/git/mymodule.git instead of just mymodule/).

I have rsa key access to the server. is your package name. You have to import it by that name, eg:

import ""

In a GOPATH legacy style environment, this will of course create the folder $GOPATH/src/ on your system.

This is how gos legacy package system works.

If you want to have it differently, you need to reconfigure your git server to serve from a different root.

You probably want to configure it, such that points to your service.

Also, I do not quite understand what you mean by “I have .go files under in the src/ directory like normal”. Do you want to say that the path points to a GOPATH like directory structure? That is not how go packages work. Take a look at a random go project at github, bitbucket, gitlab, etc, none of them has a src folder.

1 Like is the server IP address. I have to use the server IP address because if I use the server name (in /etc/hosts) go get thinks the server name is part of a package name or path.

/srv/git/ is the directory where my git repo is (mymodule.git). controller.service/ is a directory under which I have the src/ directory and under src/ I have cmd/ and internal/ directories where the .go files are. The package name under the internal/controller-service/ directory is “controller”.

Just about every git project I’ve written has a src/ directory under which are other directories containing .go files. All the .go files in one of those subdirectories belong to the same package. That’s how go packages have always worked.

The server name is part of the package name! This is how packages in go work.

Yes, thats true and I won’t object.

So it does not contain a GOPATH like structure, thats fine.

Though then the package to go get is the one that contains your go files. You can not go get empty packages.

As I said earlier, in my company we have no problems using private repositories, as long as we have those git configuration in place I mentioned earlier.

In our code it looks like this:

import ""

It works like a charm.

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