使用私有git存储库时go工作区的结构

Ive been trying to work out what the standard folder layout/structure for go code/workspaces when you are not using github.

I can see how go get works when fetching github projects, but assumedly my own git projects would not have the {github.com}/{username}/{projectname} structure that is referenced by go get and how is structed on disk after you do go get

What layout and git get url should you have when using your own git private repositories?

The package in itself carries no reference to where it is stored. You only have:

package mypackage

So, you can have your local version in your own structure, as Volker pointed out in his comment. This is the import path you use in your own projects:

import "my/custom/path/mypackage"

Then you can open source it and put mypackage onto GitHub. This will allow everyone else to get it with the go get command, but they will be using the github.com import:

import "github.com/myuser/mypackage"

This works perfectly fine unless you want to open-source packages which imports my/custom/path/mypackage. In such a case, you should consider restructuring your paths so that you use the same github import paths as the users of your package does.

From go help importpath:

For code hosted on other servers, import paths may either be qualified with the version control type, or the go tool can dynamically fetch the import path over https/http and discover where the code resides from a tag in the HTML.

To declare the code location, an import path of the form

repository.vcs/path

specifies the given repository, with or without the .vcs suffix, using the named version control system, and then the path inside that repository. The supported version control systems are:

Bazaar .bzr Git .git Mercurial .hg Subversion .svn

Then I belive you can setup your own git server with GitLab or GoGits, then your import path will be your server domain.

But If you have a private repo with github or bitbucket, your package will go-get-able. Just run a normal "go get" and you will asked to enter your password.

For unknown repo hosting sites, go get fetches the HTTP/HTTPS url first and checks if it has a meta tag linking to the git/hg/bzr repo.

See "Remote import paths".