Esempio n. 1
0
func main() {
	models.Init()
	jobs.InitJobs()

	// 设置默认404页面
	beego.ErrorHandler("404", func(rw http.ResponseWriter, r *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)
	})

	// 生产环境不输出debug日志
	if beego.AppConfig.String("runmode") == "prod" {
		beego.SetLevel(beego.LevelInformational)
	}
	beego.AppConfig.Set("version", VERSION)

	// 路由设置
	beego.Router("/", &controllers.MainController{}, "*:Index")
	beego.Router("/login", &controllers.MainController{}, "*:Login")
	beego.Router("/logout", &controllers.MainController{}, "*:Logout")
	beego.Router("/profile", &controllers.MainController{}, "*:Profile")
	beego.Router("/gettime", &controllers.MainController{}, "*:GetTime")
	beego.Router("/help", &controllers.HelpController{}, "*:Index")
	beego.AutoRouter(&controllers.TaskController{})
	beego.AutoRouter(&controllers.GroupController{})

	beego.BConfig.WebConfig.Session.SessionOn = true
	beego.Run()
}
Esempio n. 2
0
func init() {
	// config
	beego.BConfig.WebConfig.Session.SessionOn = true
	beego.BConfig.WebConfig.Session.SessionName = "SESSIONID"
	beego.BConfig.WebConfig.Session.SessionCookieLifeTime = ONE_DAYS
	beego.BConfig.WebConfig.Session.SessionGCMaxLifetime = 3600

	beego.Router("/", &controllers.HomeController{})
	beego.Router("/p/:page([0-9]+)", &controllers.HomeController{})
	beego.Router("/cat/:cat([a-zA-Z]+)", &controllers.CategoryController{})
	beego.Router("/cat/:cat([a-zA-Z]+)/p/:page([0-9]+)", &controllers.CategoryController{})
	beego.Router("/tag/:tag([a-zA-Z0-9\u4e00-\u9fa5]+)", &controllers.TagController{})
	beego.Router("/tag/:tag([a-zA-Z0-9\u4e00-\u9fa5]+)/p/:page([0-9]+)", &controllers.TagController{})
	beego.Router("/:year([0-9]{4})/:month([0-9]{2})/:day([0-9]{2})/:id([0-9]+).html", &controllers.TopicController{})
	beego.Router("/archives/:year([0-9]{4})/:month([0-9]{2})", &controllers.ArchivesController{})
	beego.Router("/message", &controllers.MessageController{})
	beego.Router("/about", &controllers.AboutController{})
	beego.Router("/search", &controllers.SearchController{})
	// admin
	beego.Router("/login", &background.AuthController{})
	beego.InsertFilter("/admin/*", beego.BeforeRouter, FilterUser)
	beego.Router("/admin/user", &background.UserController{})
	beego.Router("/admin/data", &background.DataController{})
	beego.Router("/admin/topics", &background.TopicsController{})
	beego.Router("/admin/category", &background.CategoryController{})
	beego.Router("/admin/message", &background.MessageController{})
	beego.Router("/admin/social", &background.SocialController{})
	beego.Router("/admin/blogroll", &background.BlogrollController{})
	beego.Router("/admin/ad", &background.ADController{})
	beego.Router("/admin/sysconfig", &background.SysconfigController{})
	beego.Router("/admin/databackup", &background.DataBackupRecover{})
	beego.Router("/admin/datarecover", &background.DataBackupRecover{})
	beego.Router("/admin/syslog", &background.SyslogController{})
	beego.Router("/admin/trash", &background.TrashController{})
	// proxy
	beego.Router("/proxy/:url(.*)", &proxy.ProxyController{})
	// rss
	beego.Get("/feed", feed.Feed)
	beego.Get("/sitemap", feed.SiteMap)
	beego.Get("/robots.txt", feed.Robots)
	// 404
	beego.ErrorHandler("404", HTTPNotFound)
	// redirect https
	beego.InsertFilter("*", beego.BeforeRouter, RedirectHttps)
	// plugin
	beego.Router("/plugin/useragent.html", &plugin.UserAgent{})
}