3f076f4c by astaxie

fix router like /admin/index/ should equal to /admin/index

1 parent a7791c27
Showing 1 changed file with 12 additions and 1 deletions
...@@ -146,8 +146,19 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -146,8 +146,19 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
146 //first find path from the fixrouters to Improve Performance 146 //first find path from the fixrouters to Improve Performance
147 for _, route := range p.fixrouters { 147 for _, route := range p.fixrouters {
148 n := len(requestPath) 148 n := len(requestPath)
149 //route like "/"
150 if n == 1 {
151 if requestPath == route.pattern {
152 runrouter = route
153 findrouter = true
154 break
155 } else {
156 continue
157 }
158 }
159
149 if (requestPath[n-1] != '/' && route.pattern == requestPath) || 160 if (requestPath[n-1] != '/' && route.pattern == requestPath) ||
150 (len(route.pattern) >= n && requestPath == route.pattern) { 161 (len(route.pattern) >= n && requestPath[0:n-1] == route.pattern) {
151 runrouter = route 162 runrouter = route
152 findrouter = true 163 findrouter = true
153 break 164 break
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!