Created
January 31, 2017 00:14
-
-
Save adamryman/c9acb5d8a5a88e60a5ab753afb9ea8d8 to your computer and use it in GitHub Desktop.
Revisions
-
adamryman created this gist
Jan 31, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ package main import ( "fmt" "time" "github.com/pkg/errors" flag "github.com/spf13/pflag" ) const phrase = "Hello, World!" var ( sleepStr = flag.StringP("time", "t", "1s", "sleep time between printing") ) func main() { flag.Parse() now := time.Now() sleepTime, err := time.ParseDuration(*sleepStr) if err != nil { fmt.Println(errors.Wrap(err, "cannot parse sleep time")) fmt.Println("Defaulting to one second") sleepTime = time.Second } for { fmt.Printf("%s; it has been %s since starting\n", phrase, time.Since(now).String()) time.Sleep(sleepTime) } }