Golang flag.FlagSet.Duration() function example
package flag
Duration defines a time.Duration flag with specified name(1st parameter), default value(2nd parameter), and usage string(3rd parameter). The return value is the address of a time.Duration variable that stores the value of the flag.
Golang flag.FlagSet.Duration() function usage example
package main
import (
"flag"
"fmt"
"time"
)
func main() {
flagSet := flag.NewFlagSet("check", flag.ExitOnError)
syncTimeout := flagSet.Duration("sync-timeout", 2*time.Second, "Duration of time for sync process to time out")
flag.Parse()
fmt.Println(syncTimeout)
}
Output :
2s
Reference :
Advertisement
Something interesting
Tutorials
+27.4k Golang : Convert CSV data to JSON format and save to file
+16.4k CodeIgniter/PHP : Create directory if does not exist example
+11.6k SSL : The certificate is not trusted because no issuer chain was provided
+5.7k Golang : Struct field tags and what is their purpose?
+9.3k Golang : Temperatures conversion example
+7.5k Golang : Process json data with Jason package
+16.5k Golang : File path independent of Operating System
+10.5k Generate Random number with math/rand in Go
+6.2k Golang : Extract XML attribute data with attr field tag example
+7.1k Golang : Validate credit card example
+5.4k Golang : Reclaim memory occupied by make() example
+19.2k Golang : Populate dropdown with html/template example