Adding Some Func to Go’s Flag Package
Go 1.16 is shaping up to be one of the most exciting releases of Go in recent memory. Among its new features is the //go:embed
directive and the reorganization/deprecation of io/ioutil
. It’s not due out until February 2021 (Edit: it came out Feb. 16, 2021), but now I would like to write about a minor change to the standard library flag package that might otherwise be missed in the sea of changes:
The new Func function allows registering a flag implemented by calling a function, as a lighter-weight alternative to implementing the Value interface.
I proposed and implemented flag.Func
. I have made minor contributions to the Go project before, but this is the first time I’ve added a whole top level function to the standard library, so I’d like to explain a little about what it does and the process of getting it accepted into the Go standard library.