Golang flag.FlagSet.UintVar() function example
package flag
UintVar defines a uint flag with specified name(2nd parameter), default value(3rd parameter), and usage string(4th parameter). The argument p(1st parameter) points to a uint variable in which to store the value of the flag.
Golang flag.FlagSet.UintVar() function usage example
package main
import (
"flag"
"fmt"
)
var (
flagSet *flag.FlagSet
p uint
)
func main() {
flagSet = flag.NewFlagSet("example", flag.ContinueOnError)
filecounter := flagSet.Uint("counter", 0, "transferred files counter")
flagSet.UintVar(&p, "maxcount", 50000, "maximum number of files per transfer") // <-- here
err := flagSet.Parse([]string{"counter", "maxcount"})
if err != nil {
fmt.Println(err)
}
fmt.Println(*filecounter)
fmt.Println(p)
}
Output :
0
50000
Reference :
Advertisement
Something interesting
Tutorials
+7.3k Golang : Not able to grep log.Println() output
+6.8k Golang : Muxing with Martini example
+8.2k How to show different content from website server when AdBlock is detected?
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+28.2k Golang : Connect to database (MySQL/MariaDB) server
+21.8k Golang : Convert string slice to struct and access with reflect example
+13.1k Golang : List objects in AWS S3 bucket
+19.1k Golang : Display list of time zones with GMT
+6.6k Golang : Embedded or data bundling example
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example