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
+15.7k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+13.4k Golang : error parsing regexp: invalid or unsupported Perl syntax
+10.6k Golang : How to delete element(data) from map ?
+9.5k Golang : Changing a RGBA image number of channels with OpenCV
+28.7k Golang : Detect (OS) Operating System
+5.8k Golang : Launching your executable inside a console under Linux
+8.4k Golang : Ackermann function example
+5.4k Python : Delay with time.sleep() function example
+17.6k Golang : delete and modify XML file content
+28.6k Get file path of temporary file in Go
+14.4k Golang : Parsing or breaking down URL
+7.1k Golang : A simple forex opportunities scanner