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
+29.4k Golang : JQuery AJAX post data to server and send data back to client example
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+9.4k Golang : Play .WAV file from command line
+29.5k Golang : Saving(serializing) and reading file with GOB
+16k Golang : Get sub string example
+10.1k Golang : Test a slice of integers for odd and even numbers
+7.9k Swift : Convert (cast) String to Float
+10.4k Golang : cannot assign type int to value (type uint8) in range error
+8.8k Golang : HTTP Routing with Goji example
+15.6k Golang : Validate hostname
+5.4k Unix/Linux/MacOSx : How to remove an environment variable ?
+5.3k Swift : Convert string array to array example