On this page:
There is an example:
var flagvar int
func init() {
flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
}
I understand that this is only an example, but there is no real need to
use an init() function when using the flag package.
When I first read this doc, I thought that using an init() function
was a requirement for the flag package. Other people may share the
same misunderstanding, because 2 years ago I ran into this usage pattern
in a third party library, and ran into problems when trying to compile the
library with a newer Go tool chain.
I mentioned that problem on this list:
Would it be ok if I submit a patch to the docs to remove the init()
If people use the flag package from inside an init() function and it works for them,
that won’t change, since I am not proposing a code change.
Removing init() from the example may reduce confusion for other people
who might have the same confusion that I did.
—
Craig