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
+14.9k Golang : Submit web forms without browser by http.PostForm example
+12.3k Golang : Display list of countries and ISO codes
+28.7k Golang : Detect (OS) Operating System
+46.2k Golang : Read tab delimited file with encoding/csv package
+5.7k List of Golang XML tutorials
+19.4k Golang : How to count the number of repeated characters in a string?
+6.8k Golang : Join lines with certain suffix symbol example
+5.4k Golang : Qt update UI elements with core.QCoreApplication_ProcessEvents
+7.4k Golang : Convert source code to assembly language
+16.8k Golang : Read integer from file into array
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+12.7k Golang : zlib compress file example