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
+32.1k Golang : Validate email address with regular expression
+26.4k Golang : Convert(cast) string to uint8 type and back to string
+9.9k Golang : Function wrapper that takes arguments and return result example
+25.3k Golang : Get current file path of a file or executable
+13.1k Golang : List objects in AWS S3 bucket
+7.8k Golang : Load DSA public key from file example
+5.9k Golang : Denco multiplexer example
+13.5k Golang : How to get year, month and day?
+21.1k Golang : Sort and reverse sort a slice of strings
+9k Golang : How to use Gorilla webtoolkit context package properly
+8.2k Android Studio : Rating bar example
+20.6k Nginx + FastCGI + Go Setup.