英文:
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
-
你应该遵循
$GOPATH/src/REPOSITORY_PROVIDER/USERNAME/PROJECT
的约定。所以,如果你的virtual_tree
项目位于GitHub上,那么你应该将它放在$GOPATH/src/github.com/naz/virtual_tree
目录下。 -
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
英文:
-
You should follow the convention of
$GOPATH/src/REPOSITORY_PROVIDER/USERNAME/PROJECT
. So, if yourvirtual_tree
project resides in github, then you should locate it in$GOPATH/src/github.com/naz/virtual_tree
. -
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论