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 : Apply Histogram Equalization to color images
+10.8k PHP : Convert(cast) bigInt to string
+16.9k Golang : Read integer from file into array
+5.2k Golang : Calculate half life decay example
+4.4k Golang : Valued expressions and functions example
+6.2k Golang : Extract XML attribute data with attr field tag example
+39k Golang : How to iterate over a []string(array)
+80.7k Golang : How to return HTTP status code?
+15.9k Golang : Get current time from the Internet time server(ntp) example
+4.7k Adding Skype actions such as call and chat into web page examples
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+6.9k Golang : How to setup a disk space used monitoring service with Telegram bot