go get 10.204.101.186/srv/git/mymodule.git/controller.service
but the command then fails with
package 10.204.101.186/srv/git/mymodule.git/controller.service: no Go files in /home/dean/src/golang/go3p/src/10.204.101.186/srv/git/mymodule.git/controller.service
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?
Can you give an example of an import and a go get statement that work with your private repo?
I have .go files under 10.204.101.186/srv/git/mymodule.git/controller.service 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/).
In a GOPATH legacy style environment, this will of course create the folder $GOPATH/src/10.204.101.186/srv/git/mymodule.git/controller.service 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 10.204.101.186/mymodule.git/controller.service points to your service.
Also, I do not quite understand what you mean by “I have .go files under 10.204.101.186/srv/git/mymodule.git/controller.service 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.
10.204.101.186 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.