-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 921 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"clockapp/config"
"time"
"os"
"sync"
"fmt"
)
func init() {
config.Loadconfiguration()
}
func main() {
clockApp()
}
func clockApp() {
// Stop the clock after 3 hours */
stop := time.After(3 * time.Hour)
tick := time.NewTicker(1 * time.Second)
defer tick.Stop()
/* Adding waitgroup */
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
for {
select {
case <-tick.C:
/* Logic to print min, hr and sec */
fmt.Println(ClockLogic(time.Now()))
case <-stop:
// Timeout
os.Exit(1)
}
}
}()
wg.Wait()
}
func ClockLogic(Time time.Time) string{
// Hour
if(Time.Second() == 59 && Time.Minute() == 59) {
return config.Hrstr
} else {
//Minute
if(Time.Second() == 59) {
return config.Minstr
} else {
// Second
return config.Secstr
}
}
}