Вопрос

I've been using the Go tutorial here 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?

Это было полезно?

Решение

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")
)

Другие советы

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")
)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top