forked from phachon/mm-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.go
52 lines (40 loc) · 1.38 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
package main
import (
"github.com/astaxie/beego"
"mm-wiki/app/utils"
"mm-wiki/install/controllers"
"mm-wiki/install/storage"
"net/http"
"os"
"path/filepath"
)
func init() {
storage.InstallDir, _ = filepath.Abs(filepath.Dir(os.Args[0]))
storage.RootDir = filepath.Join(storage.InstallDir, "../")
beego.AppConfig.Set("sys.name", "mm-wiki-installer")
beego.BConfig.AppName = beego.AppConfig.String("sys.name")
beego.BConfig.ServerName = beego.AppConfig.String("sys.name")
// set static path
beego.SetStaticPath("/static/", filepath.Join(storage.InstallDir, "../static"))
// views path
beego.BConfig.WebConfig.ViewsPath = filepath.Join(storage.InstallDir, "../views/")
// session
beego.BConfig.WebConfig.Session.SessionName = "mmwikiinstallssid"
beego.BConfig.WebConfig.Session.SessionOn = true
// router
beego.BConfig.WebConfig.AutoRender = false
beego.BConfig.RouterCaseSensitive = false
// todo add router..
beego.AutoRouter(&controllers.InstallController{})
beego.Router("/", &controllers.InstallController{}, "*:Index")
beego.ErrorHandler("404", http_404)
beego.ErrorHandler("500", http_500)
// add template func
beego.AddFuncMap("dateFormat", utils.NewDate().Format)
}
func http_404(rs http.ResponseWriter, req *http.Request) {
rs.Write([]byte("404 not found!"))
}
func http_500(rs http.ResponseWriter, req *http.Request) {
rs.Write([]byte("500 server error!"))
}