mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:00:57 +00:00
typo fixed
registor==>register innner ==> inner
This commit is contained in:
parent
3becd2e0d8
commit
b26ef5b2e5
2
app.go
2
app.go
@ -28,7 +28,7 @@ import (
|
|||||||
|
|
||||||
// App defines beego application with a new PatternServeMux.
|
// App defines beego application with a new PatternServeMux.
|
||||||
type App struct {
|
type App struct {
|
||||||
Handlers *ControllerRegistor
|
Handlers *ControllerRegister
|
||||||
Server *http.Server
|
Server *http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
namespace.go
38
namespace.go
@ -23,16 +23,16 @@ import (
|
|||||||
|
|
||||||
type namespaceCond func(*beecontext.Context) bool
|
type namespaceCond func(*beecontext.Context) bool
|
||||||
|
|
||||||
type innnerNamespace func(*Namespace)
|
type innerNamespace func(*Namespace)
|
||||||
|
|
||||||
// Namespace is store all the info
|
// Namespace is store all the info
|
||||||
type Namespace struct {
|
type Namespace struct {
|
||||||
prefix string
|
prefix string
|
||||||
handlers *ControllerRegistor
|
handlers *ControllerRegister
|
||||||
}
|
}
|
||||||
|
|
||||||
// get new Namespace
|
// get new Namespace
|
||||||
func NewNamespace(prefix string, params ...innnerNamespace) *Namespace {
|
func NewNamespace(prefix string, params ...innerNamespace) *Namespace {
|
||||||
ns := &Namespace{
|
ns := &Namespace{
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
handlers: NewControllerRegister(),
|
handlers: NewControllerRegister(),
|
||||||
@ -276,112 +276,112 @@ func addPrefix(t *Tree, prefix string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Condition
|
// Namespace Condition
|
||||||
func NSCond(cond namespaceCond) innnerNamespace {
|
func NSCond(cond namespaceCond) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Cond(cond)
|
ns.Cond(cond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace BeforeRouter filter
|
// Namespace BeforeRouter filter
|
||||||
func NSBefore(filiterList ...FilterFunc) innnerNamespace {
|
func NSBefore(filiterList ...FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Filter("before", filiterList...)
|
ns.Filter("before", filiterList...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace FinishRouter filter
|
// Namespace FinishRouter filter
|
||||||
func NSAfter(filiterList ...FilterFunc) innnerNamespace {
|
func NSAfter(filiterList ...FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Filter("after", filiterList...)
|
ns.Filter("after", filiterList...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Include ControllerInterface
|
// Namespace Include ControllerInterface
|
||||||
func NSInclude(cList ...ControllerInterface) innnerNamespace {
|
func NSInclude(cList ...ControllerInterface) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Include(cList...)
|
ns.Include(cList...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Router
|
// Namespace Router
|
||||||
func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) innnerNamespace {
|
func NSRouter(rootpath string, c ControllerInterface, mappingMethods ...string) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Router(rootpath, c, mappingMethods...)
|
ns.Router(rootpath, c, mappingMethods...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Get
|
// Namespace Get
|
||||||
func NSGet(rootpath string, f FilterFunc) innnerNamespace {
|
func NSGet(rootpath string, f FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Get(rootpath, f)
|
ns.Get(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Post
|
// Namespace Post
|
||||||
func NSPost(rootpath string, f FilterFunc) innnerNamespace {
|
func NSPost(rootpath string, f FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Post(rootpath, f)
|
ns.Post(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Head
|
// Namespace Head
|
||||||
func NSHead(rootpath string, f FilterFunc) innnerNamespace {
|
func NSHead(rootpath string, f FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Head(rootpath, f)
|
ns.Head(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Put
|
// Namespace Put
|
||||||
func NSPut(rootpath string, f FilterFunc) innnerNamespace {
|
func NSPut(rootpath string, f FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Put(rootpath, f)
|
ns.Put(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Delete
|
// Namespace Delete
|
||||||
func NSDelete(rootpath string, f FilterFunc) innnerNamespace {
|
func NSDelete(rootpath string, f FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Delete(rootpath, f)
|
ns.Delete(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Any
|
// Namespace Any
|
||||||
func NSAny(rootpath string, f FilterFunc) innnerNamespace {
|
func NSAny(rootpath string, f FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Any(rootpath, f)
|
ns.Any(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Options
|
// Namespace Options
|
||||||
func NSOptions(rootpath string, f FilterFunc) innnerNamespace {
|
func NSOptions(rootpath string, f FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Options(rootpath, f)
|
ns.Options(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace Patch
|
// Namespace Patch
|
||||||
func NSPatch(rootpath string, f FilterFunc) innnerNamespace {
|
func NSPatch(rootpath string, f FilterFunc) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.Patch(rootpath, f)
|
ns.Patch(rootpath, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Namespace AutoRouter
|
//Namespace AutoRouter
|
||||||
func NSAutoRouter(c ControllerInterface) innnerNamespace {
|
func NSAutoRouter(c ControllerInterface) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.AutoRouter(c)
|
ns.AutoRouter(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace AutoPrefix
|
// Namespace AutoPrefix
|
||||||
func NSAutoPrefix(prefix string, c ControllerInterface) innnerNamespace {
|
func NSAutoPrefix(prefix string, c ControllerInterface) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
ns.AutoPrefix(prefix, c)
|
ns.AutoPrefix(prefix, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Namespace add sub Namespace
|
// Namespace add sub Namespace
|
||||||
func NSNamespace(prefix string, params ...innnerNamespace) innnerNamespace {
|
func NSNamespace(prefix string, params ...innerNamespace) innerNamespace {
|
||||||
return func(ns *Namespace) {
|
return func(ns *Namespace) {
|
||||||
n := NewNamespace(prefix, params...)
|
n := NewNamespace(prefix, params...)
|
||||||
ns.Namespace(n)
|
ns.Namespace(n)
|
||||||
|
58
router.go
58
router.go
@ -110,22 +110,22 @@ type controllerInfo struct {
|
|||||||
routerType int
|
routerType int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ControllerRegistor containers registered router rules, controller handlers and filters.
|
// ControllerRegister containers registered router rules, controller handlers and filters.
|
||||||
type ControllerRegistor struct {
|
type ControllerRegister struct {
|
||||||
routers map[string]*Tree
|
routers map[string]*Tree
|
||||||
enableFilter bool
|
enableFilter bool
|
||||||
filters map[int][]*FilterRouter
|
filters map[int][]*FilterRouter
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewControllerRegister returns a new ControllerRegistor.
|
// NewControllerRegister returns a new ControllerRegister.
|
||||||
func NewControllerRegister() *ControllerRegistor {
|
func NewControllerRegister() *ControllerRegister {
|
||||||
return &ControllerRegistor{
|
return &ControllerRegister{
|
||||||
routers: make(map[string]*Tree),
|
routers: make(map[string]*Tree),
|
||||||
filters: make(map[int][]*FilterRouter),
|
filters: make(map[int][]*FilterRouter),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add controller handler and pattern rules to ControllerRegistor.
|
// Add controller handler and pattern rules to ControllerRegister.
|
||||||
// usage:
|
// usage:
|
||||||
// default methods is the same name as method
|
// default methods is the same name as method
|
||||||
// Add("/user",&UserController{})
|
// Add("/user",&UserController{})
|
||||||
@ -135,7 +135,7 @@ func NewControllerRegister() *ControllerRegistor {
|
|||||||
// Add("/api/delete",&RestController{},"delete:DeleteFood")
|
// Add("/api/delete",&RestController{},"delete:DeleteFood")
|
||||||
// Add("/api",&RestController{},"get,post:ApiFunc")
|
// Add("/api",&RestController{},"get,post:ApiFunc")
|
||||||
// Add("/simple",&SimpleController{},"get:GetFunc;post:PostFunc")
|
// Add("/simple",&SimpleController{},"get:GetFunc;post:PostFunc")
|
||||||
func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingMethods ...string) {
|
func (p *ControllerRegister) Add(pattern string, c ControllerInterface, mappingMethods ...string) {
|
||||||
reflectVal := reflect.ValueOf(c)
|
reflectVal := reflect.ValueOf(c)
|
||||||
t := reflect.Indirect(reflectVal).Type()
|
t := reflect.Indirect(reflectVal).Type()
|
||||||
methods := make(map[string]string)
|
methods := make(map[string]string)
|
||||||
@ -183,7 +183,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ControllerRegistor) addToRouter(method, pattern string, r *controllerInfo) {
|
func (p *ControllerRegister) addToRouter(method, pattern string, r *controllerInfo) {
|
||||||
if !RouterCaseSensitive {
|
if !RouterCaseSensitive {
|
||||||
pattern = strings.ToLower(pattern)
|
pattern = strings.ToLower(pattern)
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ func (p *ControllerRegistor) addToRouter(method, pattern string, r *controllerIn
|
|||||||
|
|
||||||
// only when the Runmode is dev will generate router file in the router/auto.go from the controller
|
// only when the Runmode is dev will generate router file in the router/auto.go from the controller
|
||||||
// Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
|
// Include(&BankAccount{}, &OrderController{},&RefundController{},&ReceiptController{})
|
||||||
func (p *ControllerRegistor) Include(cList ...ControllerInterface) {
|
func (p *ControllerRegister) Include(cList ...ControllerInterface) {
|
||||||
if RunMode == "dev" {
|
if RunMode == "dev" {
|
||||||
skip := make(map[string]bool, 10)
|
skip := make(map[string]bool, 10)
|
||||||
for _, c := range cList {
|
for _, c := range cList {
|
||||||
@ -243,7 +243,7 @@ func (p *ControllerRegistor) Include(cList ...ControllerInterface) {
|
|||||||
// Get("/", func(ctx *context.Context){
|
// Get("/", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) Get(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Get(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("get", pattern, f)
|
p.AddMethod("get", pattern, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ func (p *ControllerRegistor) Get(pattern string, f FilterFunc) {
|
|||||||
// Post("/api", func(ctx *context.Context){
|
// Post("/api", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) Post(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Post(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("post", pattern, f)
|
p.AddMethod("post", pattern, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ func (p *ControllerRegistor) Post(pattern string, f FilterFunc) {
|
|||||||
// Put("/api/:id", func(ctx *context.Context){
|
// Put("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) Put(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Put(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("put", pattern, f)
|
p.AddMethod("put", pattern, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ func (p *ControllerRegistor) Put(pattern string, f FilterFunc) {
|
|||||||
// Delete("/api/:id", func(ctx *context.Context){
|
// Delete("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) Delete(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Delete(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("delete", pattern, f)
|
p.AddMethod("delete", pattern, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ func (p *ControllerRegistor) Delete(pattern string, f FilterFunc) {
|
|||||||
// Head("/api/:id", func(ctx *context.Context){
|
// Head("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) Head(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Head(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("head", pattern, f)
|
p.AddMethod("head", pattern, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ func (p *ControllerRegistor) Head(pattern string, f FilterFunc) {
|
|||||||
// Patch("/api/:id", func(ctx *context.Context){
|
// Patch("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) Patch(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Patch(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("patch", pattern, f)
|
p.AddMethod("patch", pattern, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ func (p *ControllerRegistor) Patch(pattern string, f FilterFunc) {
|
|||||||
// Options("/api/:id", func(ctx *context.Context){
|
// Options("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) Options(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Options(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("options", pattern, f)
|
p.AddMethod("options", pattern, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ func (p *ControllerRegistor) Options(pattern string, f FilterFunc) {
|
|||||||
// Any("/api/:id", func(ctx *context.Context){
|
// Any("/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) Any(pattern string, f FilterFunc) {
|
func (p *ControllerRegister) Any(pattern string, f FilterFunc) {
|
||||||
p.AddMethod("*", pattern, f)
|
p.AddMethod("*", pattern, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ func (p *ControllerRegistor) Any(pattern string, f FilterFunc) {
|
|||||||
// AddMethod("get","/api/:id", func(ctx *context.Context){
|
// AddMethod("get","/api/:id", func(ctx *context.Context){
|
||||||
// ctx.Output.Body("hello world")
|
// ctx.Output.Body("hello world")
|
||||||
// })
|
// })
|
||||||
func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) {
|
func (p *ControllerRegister) AddMethod(method, pattern string, f FilterFunc) {
|
||||||
if _, ok := HTTPMETHOD[strings.ToUpper(method)]; method != "*" && !ok {
|
if _, ok := HTTPMETHOD[strings.ToUpper(method)]; method != "*" && !ok {
|
||||||
panic("not support http method: " + method)
|
panic("not support http method: " + method)
|
||||||
}
|
}
|
||||||
@ -344,7 +344,7 @@ func (p *ControllerRegistor) AddMethod(method, pattern string, f FilterFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add user defined Handler
|
// add user defined Handler
|
||||||
func (p *ControllerRegistor) Handler(pattern string, h http.Handler, options ...interface{}) {
|
func (p *ControllerRegister) Handler(pattern string, h http.Handler, options ...interface{}) {
|
||||||
route := &controllerInfo{}
|
route := &controllerInfo{}
|
||||||
route.pattern = pattern
|
route.pattern = pattern
|
||||||
route.routerType = routerTypeHandler
|
route.routerType = routerTypeHandler
|
||||||
@ -359,21 +359,21 @@ func (p *ControllerRegistor) Handler(pattern string, h http.Handler, options ...
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add auto router to ControllerRegistor.
|
// Add auto router to ControllerRegister.
|
||||||
// example beego.AddAuto(&MainContorlller{}),
|
// example beego.AddAuto(&MainContorlller{}),
|
||||||
// MainController has method List and Page.
|
// MainController has method List and Page.
|
||||||
// visit the url /main/list to execute List function
|
// visit the url /main/list to execute List function
|
||||||
// /main/page to execute Page function.
|
// /main/page to execute Page function.
|
||||||
func (p *ControllerRegistor) AddAuto(c ControllerInterface) {
|
func (p *ControllerRegister) AddAuto(c ControllerInterface) {
|
||||||
p.AddAutoPrefix("/", c)
|
p.AddAutoPrefix("/", c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add auto router to ControllerRegistor with prefix.
|
// Add auto router to ControllerRegister with prefix.
|
||||||
// example beego.AddAutoPrefix("/admin",&MainContorlller{}),
|
// example beego.AddAutoPrefix("/admin",&MainContorlller{}),
|
||||||
// MainController has method List and Page.
|
// MainController has method List and Page.
|
||||||
// visit the url /admin/main/list to execute List function
|
// visit the url /admin/main/list to execute List function
|
||||||
// /admin/main/page to execute Page function.
|
// /admin/main/page to execute Page function.
|
||||||
func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface) {
|
func (p *ControllerRegister) AddAutoPrefix(prefix string, c ControllerInterface) {
|
||||||
reflectVal := reflect.ValueOf(c)
|
reflectVal := reflect.ValueOf(c)
|
||||||
rt := reflectVal.Type()
|
rt := reflectVal.Type()
|
||||||
ct := reflect.Indirect(reflectVal).Type()
|
ct := reflect.Indirect(reflectVal).Type()
|
||||||
@ -401,7 +401,7 @@ func (p *ControllerRegistor) AddAutoPrefix(prefix string, c ControllerInterface)
|
|||||||
|
|
||||||
// Add a FilterFunc with pattern rule and action constant.
|
// Add a FilterFunc with pattern rule and action constant.
|
||||||
// The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)
|
// The bool params is for setting the returnOnOutput value (false allows multiple filters to execute)
|
||||||
func (p *ControllerRegistor) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error {
|
func (p *ControllerRegister) InsertFilter(pattern string, pos int, filter FilterFunc, params ...bool) error {
|
||||||
|
|
||||||
mr := new(FilterRouter)
|
mr := new(FilterRouter)
|
||||||
mr.tree = NewTree()
|
mr.tree = NewTree()
|
||||||
@ -420,7 +420,7 @@ func (p *ControllerRegistor) InsertFilter(pattern string, pos int, filter Filter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add Filter into
|
// add Filter into
|
||||||
func (p *ControllerRegistor) insertFilterRouter(pos int, mr *FilterRouter) error {
|
func (p *ControllerRegister) insertFilterRouter(pos int, mr *FilterRouter) error {
|
||||||
p.filters[pos] = append(p.filters[pos], mr)
|
p.filters[pos] = append(p.filters[pos], mr)
|
||||||
p.enableFilter = true
|
p.enableFilter = true
|
||||||
return nil
|
return nil
|
||||||
@ -428,7 +428,7 @@ func (p *ControllerRegistor) insertFilterRouter(pos int, mr *FilterRouter) error
|
|||||||
|
|
||||||
// UrlFor does another controller handler in this request function.
|
// UrlFor does another controller handler in this request function.
|
||||||
// it can access any controller method.
|
// it can access any controller method.
|
||||||
func (p *ControllerRegistor) UrlFor(endpoint string, values ...interface{}) string {
|
func (p *ControllerRegister) UrlFor(endpoint string, values ...interface{}) string {
|
||||||
paths := strings.Split(endpoint, ".")
|
paths := strings.Split(endpoint, ".")
|
||||||
if len(paths) <= 1 {
|
if len(paths) <= 1 {
|
||||||
Warn("urlfor endpoint must like path.controller.method")
|
Warn("urlfor endpoint must like path.controller.method")
|
||||||
@ -460,7 +460,7 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...interface{}) stri
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName string, params map[string]string, httpMethod string) (bool, string) {
|
func (p *ControllerRegister) geturl(t *Tree, url, controllName, methodName string, params map[string]string, httpMethod string) (bool, string) {
|
||||||
for k, subtree := range t.fixrouters {
|
for k, subtree := range t.fixrouters {
|
||||||
u := path.Join(url, k)
|
u := path.Join(url, k)
|
||||||
ok, u := p.geturl(subtree, u, controllName, methodName, params, httpMethod)
|
ok, u := p.geturl(subtree, u, controllName, methodName, params, httpMethod)
|
||||||
@ -575,7 +575,7 @@ func (p *ControllerRegistor) geturl(t *Tree, url, controllName, methodName strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implement http.Handler interface.
|
// Implement http.Handler interface.
|
||||||
func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
|
||||||
starttime := time.Now()
|
starttime := time.Now()
|
||||||
var runrouter reflect.Type
|
var runrouter reflect.Type
|
||||||
var findrouter bool
|
var findrouter bool
|
||||||
@ -861,7 +861,7 @@ Admin:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) {
|
func (p *ControllerRegister) recoverPanic(context *beecontext.Context) {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
if err == USERSTOPRUN {
|
if err == USERSTOPRUN {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user