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
+15.7k Golang : Get checkbox or extract multipart form data value example
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+32.5k Golang : Copy directory - including sub-directories and files
+12.6k Golang : Transform comma separated string to slice example
+7.3k Golang : Of hash table and hash map
+7.2k Golang : Dealing with postal or zip code example
+8.2k Android Studio : Rating bar example
+5.8k Golang : Markov chains to predict probability of next state example
+6.1k Golang : Scan forex opportunities by Bollinger bands
+29.5k Golang : How to create new XML file ?
+8.9k Golang : Find network service name from given port and protocol