Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
h2non committed Apr 24, 2016
1 parent e63da3c commit c86ddf8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions match.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package router

import "net/url"
import "fmt"

// Match matches the given path string againts the register pattern.
func Match(pat, path string) (url.Values, bool) {
var i, j int
p := make(url.Values)

fmt.Printf("> Test: %s %s\n", pat, path)
for i < len(path) {
switch {
case j >= len(pat):
Expand All @@ -31,6 +33,7 @@ func Match(pat, path string) (url.Values, bool) {
if j != len(pat) {
return nil, false
}

return p, true
}

Expand Down
3 changes: 3 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package router

import (
"errors"
"fmt"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -232,11 +233,13 @@ func doMatch(routes []*Route, path string) (url.Values, *Route) {
if routes == nil || len(routes) == 0 {
return nil, nil
}
fmt.Printf("> Routes: %d \n", len(routes))
for _, route := range routes {
if params, ok := route.Match(path); ok {
return params, route
}
}
fmt.Printf(">>>>>>> End matching\n")
return nil, nil
}

Expand Down

0 comments on commit c86ddf8

Please sign in to comment.