Golang flag.VisitAll() function example
package flag
VisitAll visits the command-line flags in lexicographical order, calling fn for each. It visits all flags, even those not set.
Golang flag.VisitAll() function usage example
package main
import (
"flag"
"fmt"
)
func main() {
f := flag.NewFlagSet("flag", flag.ExitOnError)
f.Int("int", 0, "int flag with value")
f.Int("int2", 0, "second 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)
fmt.Println("Visit All")
f.VisitAll(visitor) // this will display the int2 flag
}
Output :
First visit
Second visit
> int value= 108
Visit All
> int value= 108
> int2 value= 0
See https://www.socketloop.com/references/golang-flag-visit-function-example for comparison
Reference :
See also : Golang flag.Visit() function example
Advertisement
Something interesting
Tutorials
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+9.1k Golang : Intercept and compare HTTP response code example
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+13.3k Golang : Linear algebra and matrix calculation example
+20.6k Golang : Secure(TLS) connection between server and client
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+12.5k Golang : HTTP response JSON encoded data
+11.5k CodeIgniter : Import Linkedin data
+11.5k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+37.5k Upload multiple files with Go