Golang flag.DurationVar() function example
package flag
DurationVar defines a time.Duration flag with specified name (2nd parameter), default value(3rd parameter), and usage string(4th parameter). The argument p(1st parameter) points to a time.Duration variable in which to store the value of the flag.
Golang flag.DurationVar() function usage example
package main
import (
"flag"
"fmt"
"time"
)
var (
naptime = time.Millisecond * 250
nap time.Duration
)
func init() {
flag.DurationVar(&nap, "poll", naptime, "Time to wait between polling for changes")
}
func main() {
fmt.Println(flag.Lookup("poll")) // print Flag struct
fmt.Println(nap)
}
Output :
&{poll Time to wait between polling for changes 250ms 250ms}
250ms
Reference :
Advertisement
Something interesting
Tutorials
+19.2k Golang : Delete item from slice based on index/key position
+5.2k PHP : See installed compiled-in-modules
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example
+5.6k PHP : Fix Call to undefined function curl_init() error
+11.6k Android Studio : Create custom icons for your application example
+9k Golang : Get SPF and DMARC from email headers to fight spam
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+8.2k Android Studio : Rating bar example
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+7.1k Golang : Validate credit card example
+9.4k Android Studio : Indicate progression with ProgressBar example
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format