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
+9.3k Golang : How to get ECDSA curve and parameters data?
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+9.7k Golang : Sort and reverse sort a slice of floats
+62.7k Golang : Convert HTTP Response body to string
+19.4k Golang : Fix cannot download, $GOPATH not set error
+12.2k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+36.3k Golang : Convert(cast) int64 to string
+11.9k Golang : Convert(cast) bigint to string
+10.7k Golang : Underscore string example
+6.4k PHP : Proper way to get UTF-8 character or string length
+10.2k Golang : How to profile or log time spend on execution?
+5.5k Golang : Display advertisement images or strings on random order