设置环境 – $GOPATH

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

Setting up environment - $GOPATH

问题

我已经将$GOPATH定义为$HOME/go,并且在使用vim-go时,它已经将几个二进制文件(使用:GoInstallBinaries命令)安装到该文件夹中。现在的结构类似于:

--go/
----bin/
------ 一些二进制文件

----pkg/
------linux_amd64
--------- 其他目录列表

----src/
------github.com
--------其他几个目录,类似下面的目录
------golang.org
------gopg.in

我现在有些困惑,不知道在这个结构中应该从哪里开始我的项目。假设我想创建一个名为virtual_tree的项目,根据我的理解,它应该在src目录下。但是它应该在github.com目录下吗?我的项目应该放在哪里?我需要使用pkg/目录吗?我知道bin/目录包含项目的可执行文件。

谢谢!

英文:

I have defined my $GOPATH to be $HOME/go and when using vim-go, it has installed several binaries (using :GoInstallBinaries) into that folder. Now the structure is similar to:

--go/
----bin/
------ list of binaries

----pkg/
------linux_amd64
--------- list of other directories

----src/
------github.com
--------several other directories, similar with ones below
------golang.org
------gopg.in

I'm confused now where to start my own project within this structure? Say I wanted to create my own project virtual_tree, from what I understand it should be under src. But should that be inside of github.com? Where should my project go? Do I need to use pkg/ for anything? I understand that bin/ contains the executable for the project.

Thanks!

答案1

得分: 3

  1. 你应该遵循$GOPATH/src/REPOSITORY_PROVIDER/USERNAME/PROJECT的约定。所以,如果你的virtual_tree项目位于GitHub上,那么你应该将它放在$GOPATH/src/github.com/naz/virtual_tree目录下。

  2. pkg目录包含编译后的包。在该目录下创建一个描述目标架构的子目录,并且该子目录与源代码目录保持一致。

了解更多信息:

https://dave.cheney.net/2014/12/01/five-suggestions-for-setting-up-a-go-project

https://www.goinggo.net/2013/07/how-packages-work-in-go-language.html

英文:
  1. You should follow the convention of $GOPATH/src/REPOSITORY_PROVIDER/USERNAME/PROJECT. So, if your virtual_tree project resides in github, then you should locate it in $GOPATH/src/github.com/naz/virtual_tree.

  2. The pkg directory contains the compiled packages. Within that directory a sub-directory that describes the target architecture is created and that mirrors the source directories.

Read more on:

https://dave.cheney.net/2014/12/01/five-suggestions-for-setting-up-a-go-project

https://www.goinggo.net/2013/07/how-packages-work-in-go-language.html

huangapple
  • 本文由 发表于 2016年11月16日 05:02:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/40619632.html
匿名

发表评论

匿名网友

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

确定