-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmain.go
94 lines (76 loc) · 1.74 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"flag"
"os"
"sync"
"github.com/xitongsys/pangolin/client"
"github.com/xitongsys/pangolin/config"
"github.com/xitongsys/pangolin/logging"
"github.com/xitongsys/pangolin/server"
)
var configFile = flag.String("c", "cfg.json", "")
var logLevel = flag.String("l", "info", "")
func main() {
var err error
logging.Log.Info("Welcome to use Pangolin!")
defer func() {
logging.Log.Error(err)
}()
flag.Parse()
logging.SetLevel(*logLevel)
cfg, err := config.NewConfigFromFile(*configFile)
if err != nil {
os.Exit(-1)
}
logging.Log.Info(cfg.String())
if cfg.Role == "server" {
loginManager, err := server.NewLoginManager(cfg)
if err != nil {
logging.Log.Error(err)
os.Exit(-1)
}
tcpServer, err := server.NewTcpServer(cfg, loginManager)
if err != nil {
logging.Log.Error(err)
os.Exit(-1)
}
ptcpServer, err := server.NewPTcpServer(cfg, loginManager)
if err != nil {
logging.Log.Error(err)
os.Exit(-1)
}
udpServer, err := server.NewUdpServer(cfg, loginManager)
if err != nil {
logging.Log.Error(err)
os.Exit(-1)
}
loginManager.Start()
tcpServer.Start()
udpServer.Start()
ptcpServer.Start()
} else {
var tcpClient *client.TcpClient
var ptcpClient *client.PTcpClient
var udpClient *client.UdpClient
if cfg.Protocol == "tcp" {
if tcpClient, err = client.NewTcpClient(cfg); err == nil {
err = tcpClient.Start()
}
} else if cfg.Protocol == "ptcp" {
if ptcpClient, err = client.NewPTcpClient(cfg); err == nil {
err = ptcpClient.Start()
}
} else {
if udpClient, err = client.NewUdpClient(cfg); err == nil {
err = udpClient.Start()
}
}
}
if err != nil {
logging.Log.Error(err)
os.Exit(-1)
}
var wg sync.WaitGroup
wg.Add(1)
wg.Wait()
}