1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-06 02:00:18 +00:00

beego: remove app funciont & fix #590

config := tls.Config{
    ClientAuth: tls.RequireAndVerifyClientCert,
    Certificates: []tls.Certificate{cert},
    ClientCAs: pool,
}
config.Rand = rand.Reader

beego.BeeApp.Server. TLSConfig = &config
This commit is contained in:
astaxie
2014-05-20 17:28:06 +08:00
parent 04290dfc68
commit 33ad6c1370
3 changed files with 50 additions and 174 deletions

View File

@ -80,11 +80,11 @@ func (gr *GroupRouters) AddAuto(c ControllerInterface) {
func AddGroupRouter(prefix string, groups GroupRouters) *App {
for _, v := range groups {
if v.pattern == "" {
BeeApp.AutoRouterWithPrefix(prefix, v.controller)
BeeApp.Handlers.AddAutoPrefix(prefix, v.controller)
} else if v.mappingMethods != "" {
BeeApp.Router(prefix+v.pattern, v.controller, v.mappingMethods)
BeeApp.Handlers.Add(prefix+v.pattern, v.controller, v.mappingMethods)
} else {
BeeApp.Router(prefix+v.pattern, v.controller)
BeeApp.Handlers.Add(prefix+v.pattern, v.controller)
}
}
@ -93,8 +93,22 @@ func AddGroupRouter(prefix string, groups GroupRouters) *App {
// Router adds a patterned controller handler to BeeApp.
// it's an alias method of App.Router.
// usage:
// simple router
// beego.Router("/admin", &admin.UserController{})
// beego.Router("/admin/index", &admin.ArticleController{})
//
// regex router
//
// beego.Router(“/api/:id([0-9]+)“, &controllers.RController{})
//
// custom rules
// beego.Router("/api/list",&RestController{},"*:ListFood")
// beego.Router("/api/create",&RestController{},"post:CreateFood")
// beego.Router("/api/update",&RestController{},"put:UpdateFood")
// beego.Router("/api/delete",&RestController{},"delete:DeleteFood")
func Router(rootpath string, c ControllerInterface, mappingMethods ...string) *App {
BeeApp.Router(rootpath, c, mappingMethods...)
BeeApp.Handlers.Add(rootpath, c, mappingMethods...)
return BeeApp
}
@ -109,69 +123,73 @@ func RESTRouter(rootpath string, c ControllerInterface) *App {
// AutoRouter adds defined controller handler to BeeApp.
// it's same to App.AutoRouter.
// if beego.AddAuto(&MainContorlller{}) and MainController has methods List and Page,
// visit the url /main/list to exec List function or /main/page to exec Page function.
func AutoRouter(c ControllerInterface) *App {
BeeApp.AutoRouter(c)
BeeApp.Handlers.AddAuto(c)
return BeeApp
}
// AutoPrefix adds controller handler to BeeApp with prefix.
// it's same to App.AutoRouterWithPrefix.
// if beego.AutoPrefix("/admin",&MainContorlller{}) and MainController has methods List and Page,
// visit the url /admin/main/list to exec List function or /admin/main/page to exec Page function.
func AutoPrefix(prefix string, c ControllerInterface) *App {
BeeApp.AutoRouterWithPrefix(prefix, c)
BeeApp.Handlers.AddAutoPrefix(prefix, c)
return BeeApp
}
// register router for Get method
func Get(rootpath string, f FilterFunc) *App {
BeeApp.Get(rootpath, f)
BeeApp.Handlers.Get(rootpath, f)
return BeeApp
}
// register router for Post method
func Post(rootpath string, f FilterFunc) *App {
BeeApp.Post(rootpath, f)
BeeApp.Handlers.Post(rootpath, f)
return BeeApp
}
// register router for Delete method
func Delete(rootpath string, f FilterFunc) *App {
BeeApp.Delete(rootpath, f)
BeeApp.Handlers.Delete(rootpath, f)
return BeeApp
}
// register router for Put method
func Put(rootpath string, f FilterFunc) *App {
BeeApp.Put(rootpath, f)
BeeApp.Handlers.Put(rootpath, f)
return BeeApp
}
// register router for Head method
func Head(rootpath string, f FilterFunc) *App {
BeeApp.Head(rootpath, f)
BeeApp.Handlers.Head(rootpath, f)
return BeeApp
}
// register router for Options method
func Options(rootpath string, f FilterFunc) *App {
BeeApp.Options(rootpath, f)
BeeApp.Handlers.Options(rootpath, f)
return BeeApp
}
// register router for Patch method
func Patch(rootpath string, f FilterFunc) *App {
BeeApp.Patch(rootpath, f)
BeeApp.Handlers.Patch(rootpath, f)
return BeeApp
}
// register router for all method
func Any(rootpath string, f FilterFunc) *App {
BeeApp.Any(rootpath, f)
BeeApp.Handlers.Any(rootpath, f)
return BeeApp
}
// register router for own Handler
func Handler(rootpath string, h http.Handler, options ...interface{}) *App {
BeeApp.Handler(rootpath, h, options...)
BeeApp.Handlers.Handler(rootpath, h, options...)
return BeeApp
}
@ -184,15 +202,14 @@ func Errorhandler(err string, h http.HandlerFunc) *App {
return BeeApp
}
// SetViewsPath sets view directory to BeeApp.
// it's alias of App.SetViewsPath.
// SetViewsPath sets view directory path in beego application.
func SetViewsPath(path string) *App {
BeeApp.SetViewsPath(path)
ViewsPath = path
return BeeApp
}
// SetStaticPath sets static directory and url prefix to BeeApp.
// it's alias of App.SetStaticPath.
// SetStaticPath sets static directory path and proper url pattern in beego application.
// if beego.SetStaticPath("static","public"), visit /static/* to load static file in folder "public".
func SetStaticPath(url string, path string) *App {
if !strings.HasPrefix(url, "/") {
url = "/" + url
@ -203,7 +220,6 @@ func SetStaticPath(url string, path string) *App {
}
// DelStaticPath removes the static folder setting in this url pattern in beego application.
// it's alias of App.DelStaticPath.
func DelStaticPath(url string) *App {
delete(StaticDir, url)
return BeeApp
@ -212,18 +228,16 @@ func DelStaticPath(url string) *App {
// [Deprecated] use InsertFilter.
// Filter adds a FilterFunc under pattern condition and named action.
// The actions contains BeforeRouter,AfterStatic,BeforeExec,AfterExec and FinishRouter.
// it's alias of App.Filter.
func AddFilter(pattern, action string, filter FilterFunc) *App {
BeeApp.Filter(pattern, action, filter)
BeeApp.Handlers.AddFilter(pattern, action, filter)
return BeeApp
}
// InsertFilter adds a FilterFunc with pattern condition and action constant.
// The pos means action constant including
// beego.BeforeRouter, beego.AfterStatic, beego.BeforeExec, beego.AfterExec and beego.FinishRouter.
// it's alias of App.InsertFilter.
func InsertFilter(pattern string, pos int, filter FilterFunc) *App {
BeeApp.InsertFilter(pattern, pos, filter)
BeeApp.Handlers.InsertFilter(pattern, pos, filter)
return BeeApp
}