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
+9.6k Golang : How to extract video or image files from html source code
+7.8k Golang : Example of how to detect which type of script a word belongs to
+4.3k Javascript : How to show different content with noscript?
+8.9k Golang : What is the default port number for connecting to MySQL/MariaDB database ?
+33.7k Golang : All update packages with go get command
+5.3k Javascript : Change page title to get viewer attention
+5.2k PHP : See installed compiled-in-modules
+14.9k Golang : Submit web forms without browser by http.PostForm example
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+6k Golang : Experimenting with the Rejang script
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.
+16.7k Golang : Gzip file example