Skip to content

Instantly share code, notes, and snippets.

@adamryman
Created January 31, 2017 00:14
Show Gist options
  • Save adamryman/c9acb5d8a5a88e60a5ab753afb9ea8d8 to your computer and use it in GitHub Desktop.
Save adamryman/c9acb5d8a5a88e60a5ab753afb9ea8d8 to your computer and use it in GitHub Desktop.

Revisions

  1. adamryman created this gist Jan 31, 2017.
    32 changes: 32 additions & 0 deletions helloworlddoer.go
    Original 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)
    }
    }