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
+18.4k Golang : Read binary file into memory
+18.1k Golang : Check if a directory exist or not
+16.5k Golang : Get IP addresses of a domain name
+16.4k Golang : Test floating point numbers not-a-number and infinite example
+9.9k Golang : Sort and reverse sort a slice of integers
+10.2k Golang : Bcrypting password
+14k Golang : Compress and decompress file with compress/flate example
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+7.9k Javascript : How to check a browser's Do Not Track status?
+23.5k Golang : Read a file into an array or slice example
+11.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+5.9k Golang : Detect variable or constant type