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
+15.3k Golang : Delete certain files in a directory
+6k Golang : Compound interest over time example
+13.9k Golang : How to check if a file is hidden?
+8.2k Golang : Reverse text lines or flip line order example
+22.2k Golang : Convert seconds to minutes and remainder seconds
+13.6k Golang : Strings comparison
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.
+11.1k Golang : Roll the dice example
+16.6k Golang : Delete files by extension
+14.9k Golang : Submit web forms without browser by http.PostForm example
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+4.7k Unix/Linux : How to pipe/save output of a command to file?