-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
85 lines (73 loc) · 1.7 KB
/
server.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
/**
* Copyright 2014 @ ops Inc.
* name :
* author : jarryliu
* date : 2013-12-16 21:45
* description :
* history :
*/
package main
import (
"flag"
"github.com/atnet/gof"
"go2o/src/app"
"go2o/src/app/daemon"
"go2o/src/core"
"os"
"runtime"
"strings"
"fmt"
)
func main() {
var (
ch chan bool = make(chan bool)
confFile string
httpPort int
socketPort int
mode string //启动模式: h开启http,s开启socket,a开启所有
debug bool
trace bool
help bool
newApp gof.App
)
flag.IntVar(&httpPort, "port", 10022, "web server port")
flag.IntVar(&socketPort, "port2", 1001, "socket server port")
flag.StringVar(&mode, "mode", "sh", "boot mode.'h'- boot http service,'s'- boot socket service")
flag.BoolVar(&debug, "debug", false, "enable debug")
flag.BoolVar(&trace, "trace", false, "enable trace")
flag.BoolVar(&help, "help", false, "command usage")
flag.StringVar(&confFile,"conf","app.conf","")
flag.Parse()
if help {
flag.Usage()
return
}
runtime.GOMAXPROCS(runtime.NumCPU())
newApp = core.NewMainApp(confFile)
if gcx, ok := newApp.(*core.MainApp); !ok || !gcx.Init(debug, trace) {
os.Exit(1)
}
fmt.Println(newApp.Config().GetInt("server_port"),"------")
if v := newApp.Config().GetInt("server_port");v!= 0{
httpPort = v
}
if v := newApp.Config().GetInt("socket_post");v!= 0{
socketPort = v
}
core.SetGlobalApp(newApp)
app.Init(newApp)
core.RegisterTypes()
daemon.Run(newApp)
var booted bool
if strings.Contains(mode, "s") {
booted = true
go app.RunSocket(newApp, socketPort, debug, trace)
}
if strings.Contains(mode, "h") {
booted = true
go app.RunWeb(newApp, httpPort, debug, trace)
}
if booted {
<-ch
}
}