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
+11.6k Golang : Convert(cast) float to int
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+13.9k Golang : How to determine if a year is leap year?
+11.5k Golang : Handle API query by curl with Gorilla Queries example
+5.8k Linux : Disable and enable IPv4 forwarding
+20.2k Golang : How to get own program name during runtime ?
+29.1k Golang : Get first few and last few characters from string
+8.2k Golang : Qt splash screen with delay example
+7.4k Android Studio : How to detect camera, activate and capture example
+14.6k Golang : Missing Bazaar command
+20.6k Nginx + FastCGI + Go Setup.
+15.2k Golang : How to add color to string?