comparison src/1sleep/1sleep.go @ 0:de451fa0c9cd

golang repository.
author pyon@macmini
date Sat, 01 Oct 2016 11:16:31 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:de451fa0c9cd
1 package main
2
3 import(
4 "flag"
5 "fmt"
6 "time"
7 "os"
8 )
9
10 func main() {
11
12 // arguments
13 s := flag.Float64( "s", 0.99, "sleep N seconds" )
14 v := flag.Bool( "v", false, "print time" )
15 flag.Parse()
16
17 if *s > 0 {
18 sec := time.Duration( *s * 1000 ) * time.Millisecond
19 if *v {
20 fmt.Println( time.Now() )
21 }
22 time.Sleep( sec )
23 if *v {
24 fmt.Println( time.Now() )
25 }
26 } else {
27 fmt.Println( "bad time" )
28 os.Exit( 1 )
29 }
30 }
31