Golang维基构建教程:*addr未定义,为什么?

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

Golang wiki building tutorial: *addr not defined, why?

问题

我一直在使用Go教程这里,但是最终版本的main函数对我来说返回了一个错误:

$ go build wiki.go
# command-line-arguments
./wiki.go:97: undefined: addr

这是有道理的,因为在范围内(甚至在范围外)都没有定义它。如果你将main方法中的整个if函数移除,程序将能够构建和正常工作,所以不知道为什么它被包含在内,除了一些日志功能之外。

有人知道这个教程想让我做什么,或者*addr应该如何定义吗?

英文:

I've been using the Go tutorial <a href="http://golang.org/doc/articles/wiki/#tmp_12">here</a> but the final version of the main function returns an error for me:

$ go build wiki.go
# command-line-arguments
./wiki.go:97: undefined: addr

And it makes sense since this isn't defined in (or even out of) scope. If you take out the entire if-function in the main method, the program builds and works fine, so no idea why it's even included, beyond a little logging functionality.

Does anyone know what the tutorial is trying to get me to do, or how that *addr should have been defined?

答案1

得分: 0

请看完整的列表:http://golang.org/doc/articles/wiki/final.go,addr在顶部声明:

var (
    addr = flag.Bool("addr", false, "find open address and print to final-port.txt")
)
英文:

Look at the full listing here: http://golang.org/doc/articles/wiki/final.go, addr is declared at the top:

var (
    addr = flag.Bool(&quot;addr&quot;, false, &quot;find open address and print to final-port.txt&quot;)
)

答案2

得分: 0

如果你查看http://golang.org/doc/articles/wiki/final.go上的最终代码,你会看到addr被定义为一个flag.Bool。这是来自flag包的命令行标志。

17-19行代码如下:

var (
    addr = flag.Bool("addr", false, "查找空闲地址并打印到final-port.txt")
)
英文:

If you look at the final code at http://golang.org/doc/articles/wiki/final.go you'll see that addr is defined as a flag.Bool. This is a command line flag from the flag package.

Lines 17 - 19:

var (
    addr = flag.Bool(&quot;addr&quot;, false, &quot;find open address and print to final-port.txt&quot;)
)

huangapple
  • 本文由 发表于 2014年4月25日 21:26:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/23294526.html
匿名

发表评论

匿名网友

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

确定