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
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+27.2k Golang : Find files by name - cross platform example
+9.3k Golang : How to get ECDSA curve and parameters data?
+9.9k Golang : Turn string or text file into slice example
+31.6k Golang : Get local IP and MAC address
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+10.2k Golang : Random Rune generator
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+10.9k Golang : Get UDP client IP address and differentiate clients by port number
+9.4k Golang : Find the length of big.Int variable example
+4.8k Golang : A program that contain another program and executes it during run-time
+19.6k Golang : Close channel after ticker stopped example