Golang flag.FlagSet.Int() function example

package flag

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

Golang flag.FlagSet.Int() function usage example

 package main

 import (
 "flag"
 "fmt"
 )

 func main() {

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

 hour := flagSet.Int("diskchecktimeout", 1, "Disk check process time out. Default is 1 hour.")

 flag.Parse()

 fmt.Println(*hour)

 }

Output :

1

Reference :

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

Advertisement