add comments & change channel from 100 to 1000
Showing
1 changed file
with
9 additions
and
5 deletions
| ... | @@ -40,13 +40,13 @@ type controllerInfo struct { | ... | @@ -40,13 +40,13 @@ type controllerInfo struct { |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | type ControllerRegistor struct { | 42 | type ControllerRegistor struct { |
| 43 | routers []*controllerInfo | 43 | routers []*controllerInfo // regexp router storage |
| 44 | fixrouters []*controllerInfo | 44 | fixrouters []*controllerInfo // fixed router storage |
| 45 | enableFilter bool | 45 | enableFilter bool |
| 46 | filters map[int][]*FilterRouter | 46 | filters map[int][]*FilterRouter |
| 47 | enableAuto bool | 47 | enableAuto bool |
| 48 | autoRouter map[string]map[string]reflect.Type //key:controller key:method value:reflect.type | 48 | autoRouter map[string]map[string]reflect.Type //key:controller key:method value:reflect.type |
| 49 | contextBuffer chan *beecontext.Context | 49 | contextBuffer chan *beecontext.Context //context buffer pool |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | func NewControllerRegistor() *ControllerRegistor { | 52 | func NewControllerRegistor() *ControllerRegistor { |
| ... | @@ -54,7 +54,7 @@ func NewControllerRegistor() *ControllerRegistor { | ... | @@ -54,7 +54,7 @@ func NewControllerRegistor() *ControllerRegistor { |
| 54 | routers: make([]*controllerInfo, 0), | 54 | routers: make([]*controllerInfo, 0), |
| 55 | autoRouter: make(map[string]map[string]reflect.Type), | 55 | autoRouter: make(map[string]map[string]reflect.Type), |
| 56 | filters: make(map[int][]*FilterRouter), | 56 | filters: make(map[int][]*FilterRouter), |
| 57 | contextBuffer: make(chan *beecontext.Context, 100), | 57 | contextBuffer: make(chan *beecontext.Context, 1000), |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | 60 | ||
| ... | @@ -213,6 +213,10 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM | ... | @@ -213,6 +213,10 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | // add auto router to controller | 215 | // add auto router to controller |
| 216 | // example beego.AddAuto(&MainContorlller{}) | ||
| 217 | // MainController has method List and Page | ||
| 218 | // you can visit the url /main/list to exec List function | ||
| 219 | // /main/page to exec Page function | ||
| 216 | func (p *ControllerRegistor) AddAuto(c ControllerInterface) { | 220 | func (p *ControllerRegistor) AddAuto(c ControllerInterface) { |
| 217 | p.enableAuto = true | 221 | p.enableAuto = true |
| 218 | reflectVal := reflect.ValueOf(c) | 222 | reflectVal := reflect.ValueOf(c) |
| ... | @@ -367,7 +371,7 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string { | ... | @@ -367,7 +371,7 @@ func (p *ControllerRegistor) UrlFor(endpoint string, values ...string) string { |
| 367 | return "" | 371 | return "" |
| 368 | } | 372 | } |
| 369 | 373 | ||
| 370 | // AutoRoute | 374 | // main function to serveHTTP |
| 371 | func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) { | 375 | func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) { |
| 372 | defer func() { | 376 | defer func() { |
| 373 | if err := recover(); err != nil { | 377 | if err := recover(); err != nil { | ... | ... |
-
Please register or sign in to post a comment