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
+14.4k Golang : On enumeration
+13.5k Golang : Read XML elements data with xml.CharData example
+23.2k Golang : Print out struct values in string format
+10.3k Golang : Embed secret text string into binary(executable) file
+29.4k Golang : JQuery AJAX post data to server and send data back to client example
+17.6k Golang : Parse date string and convert to dd-mm-yyyy format
+19.9k Golang : Count JSON objects and convert to slice/array
+36.5k Golang : Save image to PNG, JPEG or GIF format.
+9.6k Golang : Read file with ioutil
+6.9k Golang : Normalize email to prevent multiple signups example
+6.9k Nginx : Password protect a directory/folder
+6.9k Golang : How to solve "too many .rsrc sections" error?