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 :
Advertisement
Something interesting
Tutorials
+18.6k Golang : Get download file size
+20.2k Golang : Reset or rewind io.Reader or io.Writer
+24.5k Golang : GORM read from database example
+9k Golang : How to use Gorilla webtoolkit context package properly
+6.7k Golang : Skip or discard items of non-interest when iterating example
+6.2k Golang : Get missing location after unmarshal binary and gob decode time.
+11.9k Golang : How to parse plain email text and process email header?
+9.4k Golang : Qt Yes No and Quit message box example
+24.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+25.5k Golang : Generate MD5 checksum of a file
+9.7k Golang : Sort and reverse sort a slice of floats