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.7k Golang : Add ASCII art to command line application launching process
+48.1k Golang : How to convert JSON string to map and slice
+7.7k Gogland : Where to put source code files in package directory for rookie
+12.6k Golang : Transform comma separated string to slice example
+18.2k Golang : Get command line arguments
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+11k Golang : Create Temporary File
+12.2k Golang : calculate elapsed run time
+8.1k Golang : Tell color name with OpenCV example
+16.3k Golang : Loop each day of the current month example
+10.6k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+14.4k Android Studio : Use image as AlertDialog title with custom layout example