Golang flag.FlagSet.Duration() function example

package flag

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

Golang flag.FlagSet.Duration() function usage example

 package main

 import (
 "flag"
 "fmt"
 "time"
 )

 func main() {

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

 syncTimeout := flagSet.Duration("sync-timeout", 2*time.Second, "Duration of time for sync process to time out")

 flag.Parse()

 fmt.Println(syncTimeout)

 }

Output :

2s

Reference :

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

Advertisement