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
+12.8k Swift : Convert (cast) Int or int32 value to CGFloat
+36.5k Golang : Save image to PNG, JPEG or GIF format.
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+5.2k Responsive Google Adsense
+30.4k Golang : How to verify uploaded file is image or allowed file types
+13.4k Golang : Read from buffered reader until specific number of bytes
+25.7k Golang : missing Mercurial command
+28k Golang : Move file to another directory
+25.7k Golang : How to write CSV data to file
+21.8k Golang : Convert string slice to struct and access with reflect example
+30.9k Golang : Interpolating or substituting variables in string examples
+5.9k Facebook : How to force facebook to scrape latest URL link data?