英文:
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("addr", false, "find open address and print to final-port.txt")
)
答案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("addr", false, "find open address and print to final-port.txt")
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论