Golang flag.FlagSet.Uint64() function example

package flag

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

Golang flag.FlagSet.Uint64() function usage example

 package main

 import (
 "flag"
 "fmt"
 )

 var (
 flagSet *flag.FlagSet
 p uint64
 )

 func main() {

 flagSet = flag.NewFlagSet("example", flag.ContinueOnError)

 filecounter := flagSet.Uint64("counter", 0, "transferred files counter") // <--here

 flagSet.Uint64Var(&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.Uint64

Advertisement