1
0
mirror of https://github.com/astaxie/beego.git synced 2025-02-16 23:37:04 +00:00
Beego/beego.go

89 lines
1.7 KiB
Go
Raw Normal View History

2012-12-17 13:53:03 +08:00
package beego
import (
2013-09-11 17:00:39 +08:00
"github.com/astaxie/beego/middleware"
"github.com/astaxie/beego/session"
2012-12-17 13:53:03 +08:00
"net/http"
"path"
)
2013-08-14 10:53:11 +08:00
const VERSION = "0.9.0"
2013-03-14 00:14:09 +08:00
2013-07-25 15:50:16 +08:00
func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App {
BeeApp.Router(rootpath, c, mappingMethods...)
2013-07-08 18:35:10 +08:00
return BeeApp
}
func RESTRouter(rootpath string, c ControllerInterface) *App {
Router(rootpath, c)
Router(path.Join(rootpath, ":objectId"), c)
2012-12-17 22:15:21 +08:00
return BeeApp
}
2013-07-27 10:25:14 +08:00
func AutoRouter(c ControllerInterface) *App {
BeeApp.AutoRouter(c)
return BeeApp
}
2013-05-07 00:17:25 +08:00
func Errorhandler(err string, h http.HandlerFunc) *App {
2013-09-11 17:00:39 +08:00
middleware.Errorhandler(err, h)
2013-05-07 00:17:25 +08:00
return BeeApp
}
2013-04-14 23:20:38 +08:00
func SetViewsPath(path string) *App {
BeeApp.SetViewsPath(path)
return BeeApp
}
func SetStaticPath(url string, path string) *App {
StaticDir[url] = path
return BeeApp
}
func DelStaticPath(url string) *App {
delete(StaticDir, url)
return BeeApp
}
2013-09-10 00:00:11 +08:00
//action has four values:
//BeforRouter
//AfterStatic
//BeforExec
//AfterExec
func AddFilter(pattern, action string, filter FilterFunc) *App {
BeeApp.Filter(pattern, action, filter)
2013-08-12 00:14:42 +08:00
return BeeApp
}
2012-12-17 22:15:21 +08:00
func Run() {
2013-09-10 00:00:11 +08:00
//if AppConfigPath not In the conf/app.conf reParse config
2013-05-07 23:16:56 +08:00
if AppConfigPath != path.Join(AppPath, "conf", "app.conf") {
err := ParseConfig()
if err != nil {
if RunMode == "dev" {
Warn(err)
}
2013-05-05 23:03:59 +08:00
}
}
2013-09-10 00:00:11 +08:00
2013-01-01 23:11:15 +08:00
if SessionOn {
GlobalSessions, _ = session.NewManager(SessionProvider, SessionName, SessionGCMaxLifetime, SessionSavePath)
2013-01-01 23:11:15 +08:00
go GlobalSessions.GC()
}
2013-09-10 00:00:11 +08:00
if AutoRender {
err := BuildTemplate(ViewsPath)
if err != nil {
if RunMode == "dev" {
Warn(err)
}
}
2013-03-21 21:55:54 +08:00
}
2013-09-11 17:00:39 +08:00
middleware.VERSION = VERSION
middleware.AppName = AppName
middleware.RegisterErrorHander()
2012-12-17 22:15:21 +08:00
BeeApp.Run()
}