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
+7k Web : How to see your website from different countries?
+7.1k Golang : Array mapping with Interface
+10k Golang : Get escape characters \u form from unicode characters
+22.8k Golang : untar or extract tar ball archive example
+14.2k Elastic Search : Mapping date format and sort by date
+23.9k Golang : Use regular expression to validate domain name
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+6.2k Golang & Javascript : How to save cropped image to file on server
+17.9k Golang : Login and logout a user after password verification and redirect example
+35.9k Golang : Integer is between a range
+9.4k Golang : Scramble and unscramble text message by randomly replacing words
+22.1k Golang : Join arrays or slices example