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
+20.6k Golang : Secure(TLS) connection between server and client
+7.9k Golang Hello World Example
+8.3k Golang : Oanda bot with Telegram and RSI example
+7.5k Golang : Rename part of filename
+4.8k MariaDB/MySQL : Form select statement or search query with Chinese characters
+28.5k Golang : Change a file last modified date and time
+20.7k Android Studio : AlertDialog and EditText to get user string input example
+6.9k Mac OSX : Find large files by size
+5.2k Golang : Convert lines of string into list for delete and insert operation
+6.4k PHP : Proper way to get UTF-8 character or string length
+5.6k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday