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
+6.1k Golang : Create new color from command line parameters
+6.9k How to let Facebook Login button redirect to a particular URL ?
+8.5k Golang : How to check variable or object type during runtime?
+6.9k Golang : Fibonacci number generator examples
+5.2k Responsive Google Adsense
+24.5k Golang : Change file read or write permission example
+9.7k Golang : Populate slice with sequential integers example
+10k Golang : Convert octal value to string to deal with leading zero problem
+5.8k Linux : Disable and enable IPv4 forwarding
+6.3k Golang : Test input string for unicode example