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
|
package main
import (
"fmt"
"math/rand"
"os"
"os/signal"
"time"
)
func main() {
hi := []string{"Hello", "Hola", "Bonjour",
"Ciao", "こんにちは", "안녕하세요",
"Cześć", "Olá", "Здравствуйте",
"Chào bạn", "您好", "Hallo"}
fmt.Printf("Saying hello in up to %d languages! \n", len(hi))
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
tick := time.NewTicker(1 * time.Second)
for {
select {
case <-tick.C:
r := rand.Intn(len(hi))
fmt.Println(hi[r])
case <-c:
// Got a Ctrl-C
fmt.Println("Exiting!")
os.Exit(0)
default:
time.Sleep(300 * time.Millisecond)
}
}
}
|