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
+35.1k Golang : Upload and download file to/from AWS S3
+5.6k Swift : Get substring with rangeOfString() function example
+9.4k Golang : Find the length of big.Int variable example
+13.5k Golang : Count number of runes in string
+15.2k Golang : Save(pipe) HTTP response into a file
+9.4k Golang : Generate EAN barcode
+4.6k JavaScript : Rounding number to decimal formats to display currency
+14k Golang : Reverse IP address for reverse DNS lookup example
+7.8k Golang : Example of how to detect which type of script a word belongs to
+5.5k Golang : Stop goroutine without channel
+5.6k Fix fatal error: evacuation not done in time problem
+16.5k Golang : Execute terminal command to remote machine example