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
+9.8k Golang : Format strings to SEO friendly URL example
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+6.7k Golang : When to use make or new?
+14.1k Javascript : Prompt confirmation before exit
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+19.9k Golang : Measure http.Get() execution time
+5.4k Golang : What is StructTag and how to get StructTag's value?
+8.1k Golang : How To Use Panic and Recover
+19.2k Golang : Delete item from slice based on index/key position
+13.3k Golang : Date and Time formatting
+16.1k Golang : Generate universally unique identifier(UUID) example
+11.1k Golang : Simple image viewer with Go-GTK