简体   繁体   English

设置环境 - $ GOPATH

[英]Setting up environment - $GOPATH

I have defined my $GOPATH to be $HOME/go and when using vim-go, it has installed several binaries (using :GoInstallBinaries) into that folder. 我将$GOPATH定义为$HOME/go ,当使用vim-go时,它已经在该文件夹中安装了几个二进制文件(使用:GoInstallBinaries)。 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. 假设我想创建自己的项目virtual_tree,据我所知它应该在src下。 But should that be inside of github.com? 但是,这应该在github.com内吗? Where should my project go? 我的项目应该去哪儿了? Do I need to use pkg/ for anything? 我需要使用pkg/吗? I understand that bin/ contains the executable for the project. 我理解bin/包含项目的可执行文件。

Thanks! 谢谢!

  1. You should follow the convention of $GOPATH/src/REPOSITORY_PROVIDER/USERNAME/PROJECT . 您应该遵循$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 . 因此,如果您的virtual_tree项目驻留在github中,那么您应该在$GOPATH/src/github.com/naz/virtual_tree找到它。

  2. The pkg directory contains the compiled packages. pkg目录包含已编译的包。 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://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 https://www.goinggo.net/2013/07/how-packages-work-in-go-language.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM