Golang flag.FlagSet.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.FlagSet.DurationVar() function usage example
package main
import (
"flag"
"fmt"
"time"
)
func main() {
flagSet := flag.NewFlagSet("check", flag.ExitOnError)
var p time.Duration
flagSet.DurationVar(&p, "timeout", 2*time.Second, "Disk query process time out")
flag.Parse()
fmt.Println(p)
}
Output :
2s
Reference :
Advertisement
Something interesting
Tutorials
+7.1k Golang : Validate credit card example
+14.6k Golang : How to get URL port?
+8.3k Golang : Implementing class(object-oriented programming style)
+27.6k PHP : Convert(cast) string to bigInt
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+8.2k Golang : Reverse text lines or flip line order example
+13.5k Golang : Read XML elements data with xml.CharData example
+8.6k Golang : Convert(cast) []byte to io.Reader type
+13.5k Golang : How to get year, month and day?
+11.1k Golang : Read until certain character to break for loop
+6.9k Golang : How to solve "too many .rsrc sections" error?