Golang flag.FlagSet.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.FlagSet.BoolVar() function usage example
package main
import (
"flag"
"fmt"
)
func main() {
var tocheck bool
flagSet := flag.NewFlagSet("check", flag.ExitOnError)
log := flagSet.Bool("log", false, "Log is disabled by default. If true, print out the log")
flagSet.BoolVar(&tocheck, "diskspace", true, "check empty diskspace. Default is true")
flag.Parse()
fmt.Println(tocheck)
fmt.Println(*log)
}
Output :
true
false
Reference :
Advertisement
Something interesting
Tutorials
+5.3k Swift : Convert string array to array example
+7.9k Setting $GOPATH environment variable for Unix/Linux and Windows
+17k Golang : Get input from keyboard
+12.1k Golang : Perform sanity checks on filename example
+17k Golang : Covert map/slice/array to JSON or XML format
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+14.4k Golang : How to convert a number to words
+10.6k Golang : Bubble sort example
+14k Golang : Reverse IP address for reverse DNS lookup example
+29.9k Golang : How to get HTTP request header information?
+8.2k Golang : Metaprogramming example of wrapping a function
+12.4k Elastic Search : Return all records (higher than default 10)