forked from male110/GoMvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (42 loc) · 1.22 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
// SimpleMVC project main.go
package main
import (
_ "GoMvc/Areas/Admin/Controllers"
_ "GoMvc/Controllers"
. "github.com/winq2008/GoMvc/System/Routing"
. "github.com/winq2008/GoMvc/System/Web"
"fmt"
"runtime"
"runtime/debug"
)
//当前配置文件的端口为6080,输入http://localhost:6080/可查看运行结果
//注册路由,路由注册遵循以下规则,特殊路由在先,最后是标准路由
func init() {
//Admin域的标准路由
RouteTable.AddRote(&RouteItem{
Name: "admin_area",
Url: "admin/{controller}/{action}",
Defaults: map[string]interface{}{"controller": "home", "action": "index", "area": "admin"},
})
//标准路由
RouteTable.AddRote(&RouteItem{
Name: "default",
Url: "{controller}/{action}",
Defaults: map[string]interface{}{"controller": "home", "action": "index"},
Constraints: make(map[string]string)})
}
func main() {
//程序意外退时,记录错误日志
defer func() {
if e := recover(); e != nil {
err := e.(error)
App.Log.Add(err.Error() + "\r\n" + string(debug.Stack()))
fmt.Println(err)
}
}()
//设置最大可同时执行的进程数
runtime.GOMAXPROCS(runtime.NumCPU()*2 - 1)
//监听http请求
err := App.Run()
fmt.Println(err)
}