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
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+11.4k Golang : Concatenate (combine) buffer data example
+5.6k Unix/Linux : How to find out the hard disk size?
+9.4k Golang : Scramble and unscramble text message by randomly replacing words
+18.2k Golang : Get command line arguments
+30.9k error: trying to remove "yum", which is protected
+8.7k Golang : Combine slices but preserve order example
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+7k Golang : How to call function inside template with template.FuncMap
+7.2k Golang : Dealing with postal or zip code example
+52.6k Golang : How to get struct field and value by name
+15.6k Golang : Validate hostname