简体   繁体   English

去工作区中的多个项目

[英]go get with multiple projects in workspace

In Go, the workspace contains the src, pkg and bin directories. 在Go中,工作空间包含src,pkg和bin目录。 How do I create multiple projects in the workspace, each with its own src, pkg, bin directories, such that I can 'go get' packages into the pkg directory of a particular project. 我如何在工作区中创建多个项目,每个项目都有自己的src,pkg,bin目录,这样我就可以将软件包“转到”某个特定项目的pkg目录中。

You probably do not need that. 您可能不需要。 Let's forget also the word "workspace" it's probably only confusing you. 我们还要忘记“工作区”一词,它可能只会使您感到困惑。

If you set your GOPATH environment variable that that's all you actually need to have multiple projects independently sitting on you hard disk. 如果您设置了GOPATH环境变量,那么实际要做的就是将多个项目独立地放在硬盘上。

For example, having export GOPATH="$HOME" , and performing 例如,具有export GOPATH="$HOME"并执行

$ go get github.com/foo/bar
$ go get github.com/baz/qux

Your directory tree will be 您的目录树将是

$GOPATH/pkg...
        compiled packages
$GOPATH/src/github.com/foo/bar
        bar.go
$GOPATH/src/github.com/baz/qux
        qux.go

More details here . 更多细节在这里 Note that it does talk about workspaces, but I still consider that fact very unfortunate. 请注意,它确实谈到了工作空间,但是我仍然认为这一事实非常不幸。 The earlier versions of that doc did not use nor define the concept and they were useful anyway. 该文档的早期版本未使用或定义该概念,但它们仍然很有用。 That's IMO a proof of it (the workspace) being redundant. 这是IMO的证明(工作区)是多余的。

go get is not intended to be used that way. go get不打算以这种方式使用。

all go get packages land in $GOPATH/* as described here: http://golang.org/doc/code.html#remote and there is no concept of separate workspaces. 所有go get软件包都按如下所述$GOPATH/*$GOPATH/*中: http : $GOPATH/* ,没有单独工作区的概念。

If you really want several "workspaces": Have several entries in GOPATH (separated by ":" on unix). 如果您确实想要几个“工作区”:在GOPATH中有几个条目(在Unix上用“:”分隔)。 (But most just keep everything under one GOPATH). (但是大多数只是将所有内容都保留在一个GOPATH中)。

Remember that go get fetches packages only into your first GOPATH entry. 请记住, go get 将软件包提取到您的第一个GOPATH条目中。

The other entries can be used as "seperate workspaces". 其他条目可以用作“单独的工作区”。

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

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