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
+10.4k Golang : Generate random integer or float number
+20k Golang : How to run your code only once with sync.Once object
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+9.2k Golang : How to control fmt or log print format?
+6.9k How to let Facebook Login button redirect to a particular URL ?
+9.2k Golang : does not implement flag.Value (missing Set method)
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+10k Golang : Setting variable value with ldflags
+6k PHP : How to check if an array is empty ?
+7.5k Golang : How to handle file size larger than available memory panic issue
+6k Linux/MacOSX : Search for files by filename and extension with find command
+7.5k Golang : Shuffle strings array