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 Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+15.6k Golang : Validate hostname
+13.8k Golang : Gin framework accept query string by post request example
+6.7k Golang : Derive cryptographic key from passwords with Argon2
+9k Golang : Build and compile multiple source files
+6.5k Golang : Combine slices of complex numbers and operation example
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+40.1k Golang : UDP client server read write example
+10.2k Golang : Check a web page existence with HEAD request example
+8.6k Android Studio : Import third-party library or package into Gradle Scripts
+7.5k Gogland : Single File versus Go Application Run Configurations
+5k Golang : Constant and variable names in native language