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
+6k Golang : Function as an argument type example
+9.1k Golang : Handle sub domain with Gin
+19.1k Golang : When to use public and private identifier(variable) and how to make the identifier public or private?
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+9.3k Golang : How to get garbage collection data?
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+19k Golang : Padding data for encryption and un-padding data for decryption
+6.7k Golang : When to use make or new?
+5.6k PHP : Fix Call to undefined function curl_init() error
+27.9k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+8.9k Golang : Gaussian blur on image and camera video feed examples
+4.9k HTTP common errors and their meaning explained