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
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+15.7k Golang : Get checkbox or extract multipart form data value example
+20k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+16.3k Golang : convert string or integer to big.Int type
+10.2k Golang : Use regular expression to get all upper case or lower case characters example
+23.9k Golang : Use regular expression to validate domain name
+4.1k Javascript : Empty an array example
+29.5k Golang : Saving(serializing) and reading file with GOB
+14.4k Golang : How to pass map to html template and access the map's elements
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+18.2k Golang : Put UTF8 text on OpenCV video capture image frame
+6.1k Golang : Missing Subversion command