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
+5.3k Javascript : Change page title to get viewer attention
+16.3k Golang : Loop each day of the current month example
+10.1k Golang : Get login name from environment and prompt for password
+12.8k Golang : Listen and Serve on sub domain example
+19.1k Mac OSX : Homebrew and Golang
+6k Golang : Compound interest over time example
+7.1k Golang : Validate credit card example
+23.1k Golang : simulate tail -f or read last line from log file example
+17k Golang : XML to JSON example
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+13.4k Golang : Increment string example
+9.7k PHP : Get coordinates latitude/longitude from string