/
main.go
51 lines (37 loc) · 870 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
package main
import (
"flag"
"log"
"math/rand"
"os"
"os/signal"
"syscall"
"time"
"technochat/db/redis"
"technochat/http"
)
func wait() {
signals := []os.Signal{syscall.SIGINT, syscall.SIGTERM}
ch := make(chan os.Signal, len(signals))
signal.Notify(ch, signals...)
s := <-ch
log.Println("info: got signal", s)
}
func main() {
rand.Seed(time.Now().UTC().UnixNano())
addr := flag.String("l", ":8080", "addr:port to listen on")
dbAddr := flag.String("d", "redis:6379", "addr:port of db")
flag.Parse()
db := redis.NewRedis(*dbAddr)
httpServer := http.NewServer(*addr, db)
log.Println("technochat: initialising")
httpServer.Init()
db.Init()
log.Println("technochat: successfully initialised")
log.Println("technochat: starting")
go httpServer.Routine()
wait()
httpServer.Shutdown()
db.Shutdown()
log.Println("technochat: exited")
}