go-sleep/cmd/sleep/main.go

22 lines
333 B
Go
Raw Normal View History

2020-01-20 17:45:19 +00:00
package main
2020-01-21 06:33:45 +00:00
import "os"
import "strconv"
import "fmt"
import "time"
2020-01-20 17:45:19 +00:00
func main() {
2020-01-21 06:33:45 +00:00
sleep := 1
if len(os.Args) > 1 {
var err error
sleep, err = strconv.Atoi(os.Args[1])
if err != nil {
fmt.Printf("Given %s is not a valid sleep time\n", os.Args[1])
os.Exit(1)
}
}
time.Sleep(time.Duration(sleep) * time.Second)
2020-01-20 17:45:19 +00:00
}