Go语言项目的文件夹结构约定

huangapple go评论144阅读模式
英文:

go-lang project folder structure convention

问题

我只是想确认一下,在遵循Go工具约定的情况下,Go项目中的典型项目文件夹结构的理解是否正确。

如果我正在编写一个名为my-package的包,它使用另一个第三方外部包other-package。那么根据约定,以下目录结构是否正确?

+bin
+pkg
+src
  |
  --- my-package.com/..
  |
  --- external-package.com/..

我之所以在阅读文档后再次提问,是因为与其他语言的约定不同,用户和第三方代码位于同一个顶级文件夹中。

英文:

I just wanted to confirm my understanding of a typical project folder structure in a Go project, which follows the Go tool conventions.

If i'm writing a package called my-package, which uses another 3rd party external package - other-package. Then based on conventions, is this directory structure correct ?

+bin
+pkg
+src
  |
  --- my-package.com/..
  |
  --- external-package.com/..

The reason I ask this again after reading the docs is because unlike other language conventions, the user and 3rd party code are in the same top level folder.

答案1

得分: 4

通过irc #go-nuts

用户的计算机将拥有一个共同的$GOPATH/src,用于所有项目。这个$GOPATH/src可以包含多个项目(用户的项目、外部包等)。用户只需将$GOPATH/src/mypackage提交到他们的源代码仓库中。

如果你想为你的源代码和第三方包源代码使用不同的目录,那么在$GOPATH前面添加另一个路径。go get将会将第三方包下载到该路径下。go-get会将第三方包下载到由$GOPATH指定的路径数组中找到的第一个路径中。

英文:

via irc #go-nuts

A user's machine will have a common $GOPATH/src for all projects. This $GOPATH/src could have multiple projects (user's, external packages etc.) there. The user would just commit the $GOPATH/src/mypackage to their src repo.

If you want to have separate directories for your src, and 3rd party package source, then prepend another path to $GOPATH. go get will download the 3rd party packages to that path. go-get downloads 3rd packages to the first path it finds in the array of paths specified by $GOPATH.

答案2

得分: 1

Golang在这个方面与其他语言非常不同,我可以说,在我刚开始使用Golang的几天里,理解这个主题是很困难的。我建议你将所有的项目放在$GOPATH/src目录下,并且只有一个$GOPATH。

在Golang中,我们必须适应它,就像http://golang.org/doc/code.html(代码组织)中所说的那样。

英文:

Golang is so diferent to other languages with respect this topic, I can say that in my firts days with Golang was hard to understand this topic. I recommend you to have all the proyects on $GOPATH/src and dont have more that one $GOPATH.

On GOLANG we have to adapted to it, like sa http://golang.org/doc/code.html (Code organization)

huangapple
  • 本文由 发表于 2014年4月10日 21:25:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/22989406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定