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
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+7.5k Gogland : Single File versus Go Application Run Configurations
+21.2k Golang : How to force compile or remove object files first before rebuild?
+5.3k Python : Convert(cast) string to bytes example
+6.1k Java : Human readable password generator
+14.4k Golang : How to pass map to html template and access the map's elements
+8.9k Golang : Sort lines of text example
+17.6k Golang : delete and modify XML file content
+6.4k Golang : How to search a list of records or data structures
+19k Golang : Padding data for encryption and un-padding data for decryption
+7k Golang : How to call function inside template with template.FuncMap
+6.5k Elasticsearch : Shutdown a local node