在工作区中获取多个项目。

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

go get with multiple projects in workspace

问题

在Go语言中,工作区包含src、pkg和bin目录。我如何在工作区中创建多个项目,每个项目都有自己的src、pkg和bin目录,以便我可以将包使用"go get"命令安装到特定项目的pkg目录中。

英文:

In Go, the workspace contains the src, pkg and bin directories. 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.

答案1

得分: 2

你可能不需要那个。我们也可以忘记“工作区”这个词,它可能只会让你感到困惑。

如果你设置了GOPATH环境变量,那么你实际上只需要在硬盘上独立地拥有多个项目。

例如,设置export GOPATH="$HOME",然后执行以下命令:

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

你的目录结构将会是:

$GOPATH/pkg...
        编译后的包
$GOPATH/src/github.com/foo/bar
        bar.go
$GOPATH/src/github.com/baz/qux
        qux.go

更多详细信息请参考这里。请注意,它确实提到了工作区,但我仍然认为这是非常不幸的事实。该文档的早期版本没有使用或定义这个概念,但它们仍然很有用。这在我看来证明了工作区是多余的。

英文:

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.

For example, having export GOPATH="$HOME", and performing

$ 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.

答案2

得分: 0

go get 不打算以那种方式使用。

所有的 go get 包都会按照这里描述的方式落在 $GOPATH/* 中:http://golang.org/doc/code.html#remote,并且没有独立工作区的概念。

英文:

go get is not intended to be used that way.

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.

答案3

得分: 0

如果你真的想要多个"工作空间":在GOPATH中有多个条目(在Unix上用":"分隔)。
(但大多数人都将所有内容都放在一个GOPATH下)。

请记住,go get命令只会将包下载到你的第一个GOPATH条目中。

其他条目可以用作"独立的工作空间"。

英文:

If you really want several "workspaces": Have several entries in GOPATH (separated by ":" on unix).
(But most just keep everything under one GOPATH).

Remember that go get fetches packages only into your first GOPATH entry.

The other entries can be used as "seperate workspaces".

huangapple
  • 本文由 发表于 2013年9月5日 21:30:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/18637719.html
匿名

发表评论

匿名网友

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

确定