英文:
Structure for your go workspace when using private git repository
问题
我一直在努力弄清楚在不使用GitHub时,Go代码/工作区的标准文件夹布局/结构是什么。
我可以看到在获取GitHub项目时go get
是如何工作的,但是我自己的git项目应该没有{github.com}/{username}/{projectname}
的结构,这是go get
引用的结构,并且在执行go get
后在磁盘上是如何组织的。
在使用自己的git私有存储库时,应该有什么布局和go get
的URL?
英文:
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?
答案1
得分: 6
包本身并不包含存储位置的引用。你只有:
package mypackage
所以,你可以在自己的结构中拥有你的本地版本,就像Volker在他的评论中指出的那样。这是你在自己的项目中使用的导入路径:
import "my/custom/path/mypackage"
然后你可以将其开源并将mypackage
放到GitHub上。这将允许其他人使用go get
命令获取它,但他们将使用github.com
导入:
import "github.com/myuser/mypackage"
这在大多数情况下都可以正常工作,除非你想开源导入了my/custom/path/mypackage
的包。在这种情况下,你应该考虑重新组织你的路径,以便使用与你的包的用户相同的GitHub导入路径。
英文:
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.
答案2
得分: 3
从go help importpath
中可以得知:
对于托管在其他服务器上的代码,导入路径可以使用版本控制类型进行限定,或者go工具可以通过https/http动态获取导入路径,并从HTML的标签中发现代码所在位置。
为了声明代码位置,形式为
repository.vcs/path
的导入路径指定了给定的仓库,可以带有或不带有.vcs后缀,使用指定的版本控制系统,然后是该仓库内的路径。支持的版本控制系统有:
Bazaar .bzr
Git .git
Mercurial .hg
Subversion .svn
因此,我相信你可以使用GitLab或GoGits来设置自己的git服务器,然后你的导入路径将是你的服务器域名。
但是,如果你有一个私有仓库在github或bitbucket上,你的包是可以通过go get获取的。只需运行正常的"go get"命令,然后会要求你输入密码。
英文:
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 <meta> 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.
答案3
得分: 1
对于未知的代码仓库托管站点,go get
首先获取 HTTP/HTTPS URL,并检查是否有一个元标签链接到 git/hg/bzr 仓库。
请参阅"远程导入路径"。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论