In the Go web server example here: http://golang.org/doc/effective_go.html#web_server
The following line of code works
var addr = flag.String("addr", ":1718", "http service address")
but changing it to
addr := flag.String("addr", ":1718", "http service address")
is a compilation error. Why? Does it have anything to do with the face that the return type of the function is *string
instead of string
? What difference does that make?
UPDATE: Thanks for pointing out that :=
is not allowed at the top level. Any idea why this inconsistency is in the spec? I don't see any reason for the behaviour to be different inside a block.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…