forked from phachon/mm-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
69 lines (60 loc) · 2.44 KB
/
router.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
package main
import (
"github.com/astaxie/beego"
"mm-wiki/app/controllers"
systemControllers "mm-wiki/app/modules/system/controllers"
"mm-wiki/app/utils"
"net/http"
"html/template"
)
func init() {
initRouter()
}
func initRouter() {
// router
beego.BConfig.WebConfig.AutoRender = false
beego.BConfig.RouterCaseSensitive = false
beego.Router("/", &controllers.MainController{}, "*:Index")
beego.Router("/author", &controllers.AuthorController{}, "*:Index")
beego.AutoRouter(&controllers.AuthorController{})
beego.AutoRouter(&controllers.MainController{})
beego.AutoRouter(&controllers.SpaceController{})
beego.AutoRouter(&controllers.CollectionController{})
beego.AutoRouter(&controllers.FollowController{})
beego.AutoRouter(&controllers.UserController{})
beego.AutoRouter(&controllers.DocumentController{})
beego.AutoRouter(&controllers.PageController{})
beego.AutoRouter(&controllers.ImageController{})
systemNamespace := beego.NewNamespace("/system",
beego.NSAutoRouter(&systemControllers.MainController{}),
beego.NSAutoRouter(&systemControllers.ProfileController{}),
beego.NSAutoRouter(&systemControllers.UserController{}),
beego.NSAutoRouter(&systemControllers.RoleController{}),
beego.NSAutoRouter(&systemControllers.PrivilegeController{}),
beego.NSAutoRouter(&systemControllers.SpaceController{}),
beego.NSAutoRouter(&systemControllers.Space_UserController{}),
beego.NSAutoRouter(&systemControllers.LogController{}),
beego.NSAutoRouter(&systemControllers.EmailController{}),
beego.NSAutoRouter(&systemControllers.LinkController{}),
beego.NSAutoRouter(&systemControllers.AuthController{}),
beego.NSAutoRouter(&systemControllers.ConfigController{}),
beego.NSAutoRouter(&systemControllers.ContactController{}),
beego.NSAutoRouter(&systemControllers.StaticController{}),
)
beego.AddNamespace(systemNamespace)
beego.ErrorHandler("404", http_404)
beego.ErrorHandler("500", http_500)
// add template func
beego.AddFuncMap("dateFormat", utils.NewDate().Format)
}
func http_404(rw http.ResponseWriter, req *http.Request) {
t,_:= template.New("404.html").ParseFiles(beego.BConfig.WebConfig.ViewsPath+"/error/404.html")
data := make(map[string]interface{})
data["content"] = "page not found"
t.Execute(rw, data)
}
func http_500(rw http.ResponseWriter, req *http.Request) {
t, _ := template.New("500.html").ParseFiles(beego.BConfig.WebConfig.ViewsPath + "/error/500.html")
data := make(map[string]interface{})
t.Execute(rw, data)
}