-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
54 lines (44 loc) · 918 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
package main
import (
"P2P-Crypto-Chat/common"
"P2P-Crypto-Chat/peer"
"flag"
"os"
"path/filepath"
)
var defaultLogFilename = "chat.log"
func main() {
//获取配置文件路径
cfgFile := flag.String("c", "", "configure file")
flag.Parse()
//判断配置文件是否存在
if _, err := os.Stat(*cfgFile); os.IsNotExist(err) {
panic(err)
}
cfg := common.LoadConfig(*cfgFile)
//设置日志
initLogRotator(filepath.Join(cfg.LogDir, defaultLogFilename))
defer func() {
if logRotator != nil {
logRotator.Close()
}
}()
setLogLevels(cfg.LogLevel)
interrupt := interruptListener()
if interruptRequested(interrupt) {
return
}
startService(cfg)
defer func() {
log.Infof("Gracefully shutting down the server...")
stopService()
log.Infof("Server shutdown complete")
}()
<- interrupt
}
func startService(cfg common.Config) {
peer.Start(cfg)
}
func stopService(){
peer.Stop()
}