-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (48 loc) · 1.13 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
package main
import (
"flag"
"fmt"
"github.com/iotames/easyim/config"
"github.com/iotames/easyim/database"
"github.com/iotames/easyim/server"
)
var (
daemon bool // 以守护进程方式后台运行
stop bool // 停止程序
appInit bool
sconf config.Server
)
func main() {
var err error
flag.Parse()
if stop {
stopApp(sconf.ApiPort)
return
}
if daemon {
err = startDaemon()
if err != nil {
fmt.Println("start daemon err:", err)
return
}
return
}
if appInit {
database.SyncTables()
}
server := server.NewServer(sconf)
err = server.Start()
if err != nil {
fmt.Println("EasyIM start fail:", err)
}
}
func init() {
config.LoadEnv()
sconf = config.GetServer()
flag.IntVar(&sconf.Port, "port", sconf.Port, "监听的端口号")
flag.IntVar(&sconf.ApiPort, "apiport", sconf.ApiPort, "Api接口监听的端口号")
flag.BoolVar(&daemon, "d", false, "以守护进程的方式在后台运行。不支持windows系统")
flag.BoolVar(&stop, "stop", false, "停止运行中的程序")
flag.BoolVar(&appInit, "init", false, "首次运行时添加,用于初始化")
// time.LoadLocation("Asia/Shanghai")
}