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
+17.7k How to enable MariaDB/MySQL logs ?
+16.8k Golang : Get own process identifier
+7.5k Gogland : Single File versus Go Application Run Configurations
+7.2k Golang : Null and nil value
+21.1k Golang : Sort and reverse sort a slice of strings
+6.5k Golang : Handling image beyond OpenCV video capture boundary
+6.9k How to let Facebook Login button redirect to a particular URL ?
+13.9k Golang : How to check if a file is hidden?
+24k Golang : Call function from another package
+7.5k Golang : Handling Yes No Quit query input
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+26.3k Golang : Calculate future date with time.Add() function