Beego/beego.go

111 lines
2.1 KiB
Go
Raw Normal View History

2012-12-17 05:53:03 +00:00
package beego
import (
"net/http"
"path"
2013-10-28 15:30:16 +00:00
"strings"
2013-12-03 11:26:51 +00:00
"github.com/astaxie/beego/middleware"
"github.com/astaxie/beego/session"
2012-12-17 05:53:03 +00:00
)
2013-12-19 13:09:45 +00:00
const VERSION = "1.0.0"
2013-03-13 16:14:09 +00:00
2013-07-25 07:50:16 +00:00
func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App {
BeeApp.Router(rootpath, c, mappingMethods...)
2013-07-08 10:35:10 +00:00
return BeeApp
}
func RESTRouter(rootpath string, c ControllerInterface) *App {
Router(rootpath, c)
Router(path.Join(rootpath, ":objectId"), c)
2012-12-17 14:15:21 +00:00
return BeeApp
}
2013-07-27 02:25:14 +00:00
func AutoRouter(c ControllerInterface) *App {
BeeApp.AutoRouter(c)
return BeeApp
}
2013-05-06 16:17:25 +00:00
func Errorhandler(err string, h http.HandlerFunc) *App {
2013-09-11 09:00:39 +00:00
middleware.Errorhandler(err, h)
2013-05-06 16:17:25 +00:00
return BeeApp
}
2013-04-14 15:20:38 +00:00
func SetViewsPath(path string) *App {
BeeApp.SetViewsPath(path)
return BeeApp
}
func SetStaticPath(url string, path string) *App {
2013-10-28 15:30:16 +00:00
if !strings.HasPrefix(url, "/") {
url = "/" + url
}
2013-04-14 15:20:38 +00:00
StaticDir[url] = path
return BeeApp
}
func DelStaticPath(url string) *App {
delete(StaticDir, url)
return BeeApp
}
//!!DEPRECATED!! use InsertFilter
2013-09-09 16:00:11 +00:00
//action has four values:
//BeforRouter
//AfterStatic
//BeforExec
//AfterExec
func AddFilter(pattern, action string, filter FilterFunc) *App {
BeeApp.Filter(pattern, action, filter)
2013-08-11 16:14:42 +00:00
return BeeApp
}
func InsertFilter(pattern string, pos int, filter FilterFunc) *App {
2013-12-03 11:26:51 +00:00
BeeApp.InsertFilter(pattern, pos, filter)
return BeeApp
}
2012-12-17 14:15:21 +00:00
func Run() {
2013-12-04 15:53:36 +00:00
// if AppConfigPath not In the conf/app.conf reParse config
2013-12-04 09:03:49 +00:00
if AppConfigPath != path.Join(AppPath, "conf", "app.conf") {
err := ParseConfig()
if err != nil {
2013-12-04 15:53:36 +00:00
// configuration is critical to app, panic here if parse failed
panic(err)
2013-12-04 09:03:49 +00:00
}
}
2013-09-09 16:00:11 +00:00
2013-12-07 07:16:32 +00:00
//init mime
initMime()
2013-01-01 15:11:15 +00:00
if SessionOn {
GlobalSessions, _ = session.NewManager(SessionProvider,
SessionName,
SessionGCMaxLifetime,
SessionSavePath,
HttpTLS,
SessionHashFunc,
SessionHashKey,
SessionCookieLifeTime)
2013-01-01 15:11:15 +00:00
go GlobalSessions.GC()
}
2013-09-09 16:00:11 +00:00
2013-09-19 15:40:55 +00:00
err := BuildTemplate(ViewsPath)
if err != nil {
if RunMode == "dev" {
Warn(err)
}
2013-03-21 13:55:54 +00:00
}
2013-09-11 09:00:39 +00:00
middleware.VERSION = VERSION
middleware.AppName = AppName
middleware.RegisterErrorHander()
if EnableAdmin {
go BeeAdminApp.Run()
}
2012-12-17 14:15:21 +00:00
BeeApp.Run()
}