-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
71 lines (54 loc) · 1.3 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
//
// main
//
package main
import (
"masterlab_socket/area"
"masterlab_socket/cmd"
"masterlab_socket/connector"
"masterlab_socket/cron"
"masterlab_socket/global"
"masterlab_socket/golog"
"masterlab_socket/hub"
"masterlab_socket/lib/syncmap"
_ "net/http/pprof"
"runtime"
)
// 初始化全局变量
func initGlobal() {
global.SumConnections = 0
global.Qps = 0
// 先在global声明,再使用make函数创建一个非nil的map,nil map不能赋值
global.AuthCmds = make([]string, 0)
global.UserSessions = syncmap.New()
global.SingleMode = global.Config.SingleMode
global.AuthCmds = global.Config.Connector.AuthCcmds
area.UserJoinedAreas = syncmap.New()
global.InitWorkerAddr()
}
/**
* 框架启动
*/
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
cmd.Execute();
// 初始化配置和全局变量
global.InitConfig()
golog.InitLogger()
initGlobal()
// 前端的socket服务
frontSocket := new(connector.Connector)
go frontSocket.Socket("", global.Config.Connector.SocketPort)
go frontSocket.Websocket("", global.Config.Connector.WebsocketPort)
// 开启hub服务器
hubObj := new(hub.Hub)
go hubObj.Server()
// 预创建多个场景
go area.InitConfig()
// 计划任务
schedule := new(cron.Schedule)
go schedule.Run()
golog.Info("Server started!")
//go build;
select {}
}