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
+41.2k Golang : How to count duplicate items in slice/array?
+10.6k Golang : ISO8601 Duration Parser example
+6.8k Golang : Get expvar(export variables) to work with multiplexer
+17.6k Convert JSON to CSV in Golang
+7.5k Golang : Create zip/ePub file without compression(use Store algorithm)
+9.6k Golang : Copy map(hash table) example
+8.8k Android Studio : Image button and button example
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+10.1k Golang : Identifying Golang HTTP client request
+21.2k Golang : Get password from console input without echo or masked
+11.5k Golang : Change date format to yyyy-mm-dd
+35.3k Golang : Strip slashes from string example