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
+16k Golang : Get sub string example
+19.6k Golang : Get current URL example
+10.3k Golang : Convert file content to Hex
+11.3k Golang : Post data with url.Values{}
+7.9k Swift : Convert (cast) String to Float
+9k Golang : Populate or initialize struct with values example
+18k Golang : How to log each HTTP request to your web server?
+28k Golang : Move file to another directory
+20.5k nginx: [emerg] unknown directive "passenger_enabled"
+5.5k Golang : Stop goroutine without channel
+4.7k Golang : How to pass data between controllers with JSON Web Token