Golang flag.FlagSet.Visit() function example
package flag
Visit visits the flags in lexicographical order, calling fn(1st parameter) for each. It visits only those flags that have been set.
Golang flag.FlagSet.Visit() function usage example
package main
import (
"flag"
"fmt"
)
func main() {
f := flag.NewFlagSet("flag", flag.ExitOnError)
f.Int("int", 0, "int flag with value")
visitor := func(a *flag.Flag) {
fmt.Println(">", a.Name, "value=", a.Value)
}
fmt.Println("First visit")
f.Visit(visitor) // no value assigned
f.Parse([]string{"-int", "108"}) // visit flag set earlier and assign value
fmt.Println("Second visit")
f.Visit(visitor)
}
Output :
First visit
Second visit
> int value= 108
Reference :
Advertisement
Something interesting
Tutorials
+6.5k Golang : Handling image beyond OpenCV video capture boundary
+9.4k Golang : Generate EAN barcode
+16.1k Golang : How to check if input from os.Args is integer?
+11.8k Golang : GTK Input dialog box examples
+7.7k Golang : How to execute code at certain day, hour and minute?
+8.1k Golang : Tell color name with OpenCV example
+21.8k Golang : Convert string slice to struct and access with reflect example
+13.6k Android Studio : Password input and reveal password example
+37.5k Upload multiple files with Go
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image