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
+6k Javascript : Get operating system and browser information
+10k Golang : Setting variable value with ldflags
+17.8k Golang : Defer function inside init()
+5.7k Linux/Unix/PHP : Restart PHP-FPM
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+10.8k Golang : Natural string sorting example
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+14.2k Golang : syscall.Socket example
+12.6k Golang : Transform comma separated string to slice example
+51.1k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+8.9k Golang : Gaussian blur on image and camera video feed examples
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)