Skip to content

Commit

Permalink
Use for ... range inside New
Browse files Browse the repository at this point in the history
New walks over the range of segment values but does not alter or append
to segments, so we can use for range to reduce the length of the
function by 1 line.
  • Loading branch information
davecheney committed May 21, 2017
1 parent 941d7ae commit 1e8f34d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ func New(path string, handler interface{}) Router {

// prepare and validate pattern segments to match
segments := strings.Split(strings.Trim(p, "/"), "/")
for i := 0; i < len(segments); i++ {
seg := segments[i]
for i, seg := range segments {
segments[i] = "/" + seg
if pos := strings.IndexAny(seg, ":*"); pos == -1 {
continue
Expand Down

0 comments on commit 1e8f34d

Please sign in to comment.