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
+6.1k PageSpeed : Clear or flush cache on web server
+9.4k Golang : Find the length of big.Int variable example
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+7.4k Golang : Word limiter example
+7.5k Golang : Handling Yes No Quit query input
+13.7k Golang : Activate web camera and broadcast out base64 encoded images
+5.4k Golang : What is StructTag and how to get StructTag's value?
+15.8k Golang : Get digits from integer before and after given position example
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+10.9k Golang : Removes punctuation or defined delimiter from the user's input
+24.5k Golang : Time slice or date sort and reverse sort example
+9.5k Golang : Changing a RGBA image number of channels with OpenCV