Golang flag.FlagSet.IntVar() function example

package flag

IntVar defines an int flag with specified name(2nd parameter), default value(3rd parameter), and usage string(4th parameter). The argument p(1st parameter) points to an int variable in which to store the value of the flag.

Golang flag.FlagSet.IntVar() function usage example

 package main

 import (
 "flag"
 "fmt"
 )

 func main() {

 flagSet := flag.NewFlagSet("check", flag.ExitOnError)

 var p int

 flagSet.IntVar(&p, "diskchecktimeout", 1, "Disk check process time out. Default is 1 hour.")

 flag.Parse()

 fmt.Println(p)

 }

Reference :

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

Advertisement