Golang flag.FlagSet.Uint() function example

package flag

Uint defines a uint flag with specified name(1st parameter), default value(2nd parameter), and usage string(3rd parameter). The return value is the address of a uint variable that stores the value of the flag.

Golang flag.FlagSet.Uint() 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") // <-- here


 flagSet.UintVar(&p, "maxcount", 50000, "maximum number of files per transfer")

 err := flagSet.Parse([]string{"counter", "maxcount"})

 if err != nil {
 fmt.Println(err)
 }


 fmt.Println(*filecounter)
 fmt.Println(p)
 }

Output :

0

50000

Reference :

http://golang.org/pkg/flag/#FlagSet.Uint

Advertisement