Golang flag.Duration() function example
package flag
Duration defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag.
Golang flag.Duration() function usage example
package main
import (
"flag"
"fmt"
"time"
)
var buildTimeout = flag.Duration("buildTimeout", 60*time.Minute, "Maximum time to wait for builds and tests")
func runTimeout(timeout time.Duration) {
fmt.Println(timeout)
}
func main() {
fmt.Println(flag.Lookup("buildTimeout")) // print Flag struct
runTimeout(*buildTimeout)
}
Output :
&{buildTimeout Maximum time to wait for builds and tests 1h0m0s 1h0m0s}
1h0m0s
Reference :
Advertisement
Something interesting
Tutorials
+8.9k Golang : Get current, epoch time and display by year, month and day
+5.6k Golang : When to use make or new?
+29.3k Golang : How to convert(cast) string to IP address?
+18.3k Golang : Archive directory with tar and gzip
+6.8k Golang : Check from web if Go application is running or not
+7.4k Golang : Implementing class(object-oriented programming style)
+3.8k Python : Find out the variable type and determine the type with simple test
+5k Golang : Detect variable or constant type
+14.1k Golang : How do I get the local IP (non-loopback) address ?
+7.8k Golang : Get curl -I or head data from URL example
+5.1k Golang : Missing Subversion command
+15.2k Golang : Convert slice to array