为什么我无法使用go get获取gotour?

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

Why can't I get the gotour with go get?

问题

所以我决定学习go,然后我开始了tour。在tour的第三阶段中,他们建议使用go来检出tour的副本并在本地运行,所以我通过推荐的安装程序包在mac上安装了go。

然后我可以使用go命令,所以我按照tour中的建议运行了go get code.google.com/p/go-tour/gotour

在tour中它说“然后运行生成的gotour可执行文件”。但是我找不到可执行文件。

go get的输出是这样的:

package code.google.com/p/go-tour/gotour: Get https://code.google.com/p/go-tour/source/checkout?repo=: EOF

我知道EOF表示文件结束,但我不确定这是否是错误消息。

我已经安装了hg

$ hg --version
Mercurial Distributed SCM (version 2.3.1)

并且我设置了我的$GOPATH(但文件没有出现在那里):

echo $GOPATH
/Users/alex/.golib

运行go env返回以下内容:

GOROOT="/usr/local/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="darwin"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="darwin"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread -fno-common"
CGO_ENABLED="1"

如果有帮助的话,我正在使用fish作为我的shell。

我做错了什么?

英文:

So I decided I wanted to learn go, and so I started the tour. In stage 3 of that tour they recommend to use go to checkout a copy of the tour and run it locally, so I installed go for mac via the recommended installer package.

I then had the go command available, so I ran go get code.google.com/p/go-tour/gotour as it suggests in the tour.

It says "and then run the resultant gotour executable" in the tour. No executable was to be found.

The output from go get was this:

package code.google.com/p/go-tour/gotour: Get https://code.google.com/p/go-tour/source/checkout?repo=: EOF

I know EOF means end of file but I'm not sure as to whether that was an error message or not.

I have hg installed:

$ hg --version
Mercurial Distributed SCM (version 2.3.1)

And I set my $GOPATH (and the file doesn't appear there):

echo $GOPATH
/Users/alex/.golib

Running go env returns this:

GOROOT="/usr/local/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="darwin"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="darwin"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread -fno-common"
CGO_ENABLED="1"

If it helps, I'm using fish as my shell.

What am I doing wrong?

答案1

得分: 2

一个 go get(与 go get -u 相反)将会获取、编译并安装你想要的 Go 模块到 $GOPATH 中。可执行文件 gotour 将会在 $GOPATH/bin 中。

所以请确保你的 $GOPATH/bin 在你的路径中。

当执行时,你应该看到:

2012/09/15 10:43:57 从 $GOPATH/src/code.google.com/p/go-tour 提供内容
2012/09/15 10:43:57 打开你的网页浏览器并访问 http://127.0.0.1:3999/

注意(个人偏好):我会使用一个更可见的路径,而不是 /Users/alex/.golib/Users/alex/go
GOPATH 不仅仅是为了获取一些库,而是为了开发你的所有 Go 项目。

英文:

a go get (contrary to go get -u) will get, compile and install the go module you want in $GOPATH.
The executable gotour will be in $GOPATH/bin.

So make sure you have your $GOPATH/bin in your path.

When executed, you should see:

2012/09/15 10:43:57 Serving content from $GOPATH/src/code.google.com/p/go-tour
2012/09/15 10:43:57 Open your web browser and visit http://127.0.0.1:3999/

Note (personal preference): I would use a more visible path than /Users/alex/.golib: /Users/alex/go
GOPATH isn't just to get some libs, but to develop all your go projects.

huangapple
  • 本文由 发表于 2012年9月15日 15:11:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/12435348.html
匿名

发表评论

匿名网友

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

确定