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
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+14.4k Golang : On enumeration
+20.2k Golang : Count number of digits from given integer value
+8.7k Golang : How to join strings?
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+10.3k Golang : Embed secret text string into binary(executable) file
+15.6k Golang : rune literal not terminated error
+12.4k Golang : Search and extract certain XML data example
+5.7k Get website traffic ranking with Similar Web or Alexa
+8.6k Golang : Convert(cast) []byte to io.Reader type
+6.7k Golang : Derive cryptographic key from passwords with Argon2
+6.6k Golang : Warp text string by number of characters or runes example