Golang flag.BoolVar() function example
package flag
BoolVar defines a bool flag with specified name(2nd parameter), default value(3rd parameter), and usage string(4th parameter). The argument p(1st parameter) points to a bool variable in which to store the value of the flag.
Golang flag.BoolVar() function usage example
package main
import (
"flag"
"fmt"
)
var usejson bool
func init() {
flag.BoolVar(&usejson, "usejson", false, "When true, produce result in JSON blocks. Default : 'false'")
}
func main() {
fmt.Println(usejson) // print boolean value
fmt.Println(flag.Lookup("usejson")) // print Flag struct
}
Output :
false
&{usejson When true, produce result in JSON blocks. Default : 'false' false false}
Reference :
Advertisement
Something interesting
Tutorials
+9.4k Golang : Generate EAN barcode
+12.7k Golang : Sort and reverse sort a slice of bytes
+6.5k Golang : Convert an executable file into []byte example
+8.8k Golang : Executing and evaluating nested loop in html template
+16.8k Golang : Get own process identifier
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+5.2k PHP : See installed compiled-in-modules
+5.5k Clean up Visual Studio For Mac installation failed disk full problem
+6.3k Golang : Detect face in uploaded photo like GPlus
+13.9k Golang : How to determine if a year is leap year?
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier