70.5 KB
golang-github-julienschmidt-httprouter version 1.3.0-1~jan+unchanged1 (unchanged) vs.
golang-github-julienschmidt-httprouter version 1.3.0+git20200921.1.fe77dd0-1~jan+nus1 (fresh-snapshots)
70.4 KB
golang-github-julienschmidt-httprouter-dev_1.3.0-1~jan+unchanged1_all.deb vs.
golang-github-julienschmidt-httprouter-dev_1.3.0+git20200921.1.fe77dd0-1~jan+nus1_all.deb
452 B
file list
    
Offset 1, 3 lines modifiedOffset 1, 3 lines modified
1 -rw-r--r--···0········0········0········4·2021-01-16·20:24:04.000000·debian-binary1 -rw-r--r--···0········0········0········4·2021-01-16·20:24:04.000000·debian-binary
2 -rw-r--r--···0········0········0·····1116·2021-01-16·20:24:04.000000·control.tar.xz2 -rw-r--r--···0········0········0·····1128·2021-01-16·20:24:04.000000·control.tar.xz
3 -rw-r--r--···0········0········0····18112·2021-01-16·20:24:04.000000·data.tar.xz3 -rw-r--r--···0········0········0····19460·2021-01-16·20:24:04.000000·data.tar.xz
1.12 KB
control.tar.xz
1.09 KB
control.tar
411 B
file list
    
Offset 1, 3 lines modifiedOffset 1, 3 lines modified
1 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./1 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./
2 -rw-r--r--···0·root·········(0)·root·········(0)·····1026·2021-01-16·20:24:04.000000·./control2 -rw-r--r--···0·root·········(0)·root·········(0)·····1042·2021-01-16·20:24:04.000000·./control
3 -rw-r--r--···0·root·········(0)·root·········(0)······923·2021-01-16·20:24:04.000000·./md5sums3 -rw-r--r--···0·root·········(0)·root·········(0)······923·2021-01-16·20:24:04.000000·./md5sums
639 B
./control
    
Offset 1, 13 lines modifiedOffset 1, 13 lines modified
1 Package:·golang-github-julienschmidt-httprouter-dev1 Package:·golang-github-julienschmidt-httprouter-dev
2 Source:·golang-github-julienschmidt-httprouter2 Source:·golang-github-julienschmidt-httprouter
3 Version:·1.3.0-1~jan+unchanged13 Version:·1.3.0+git20200921.1.fe77dd0-1~jan+nus1
4 Architecture:·all4 Architecture:·all
5 Maintainer:·Debian·Go·Packaging·Team·<team+pkg-go@tracker.debian.org>5 Maintainer:·Debian·Go·Packaging·Team·<team+pkg-go@tracker.debian.org>
6 Installed-Size:·876 Installed-Size:·94
7 Breaks:·burrow·(<<·1.2.1-2)7 Breaks:·burrow·(<<·1.2.1-2)
8 Section:·golang8 Section:·golang
9 Priority:·optional9 Priority:·optional
10 Multi-Arch:·foreign10 Multi-Arch:·foreign
11 Homepage:·https://github.com/julienschmidt/httprouter11 Homepage:·https://github.com/julienschmidt/httprouter
12 Description:·High·performance·HTTP·request·router·for·Go·that·scales·well12 Description:·High·performance·HTTP·request·router·for·Go·that·scales·well
13 ·HttpRouter·(github.com/julienschmidt/httprouter)·is·a·lightweight·high13 ·HttpRouter·(github.com/julienschmidt/httprouter)·is·a·lightweight·high
48.0 B
./md5sums
30.0 B
./md5sums
Files differ
68.6 KB
data.tar.xz
68.6 KB
data.tar
3.61 KB
file list
    
Offset 1, 19 lines modifiedOffset 1, 19 lines modified
1 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./1 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./
2 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/2 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/
3 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/3 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/
4 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/doc/4 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/doc/
5 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/doc/golang-github-julienschmidt-httprouter-dev/5 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/doc/golang-github-julienschmidt-httprouter-dev/
6 -rw-r--r--···0·root·········(0)·root·········(0)·····1092·2021-01-16·20:24:04.000000·./usr/share/doc/golang-github-julienschmidt-httprouter-dev/changelog.Debian.gz6 -rw-r--r--···0·root·········(0)·root·········(0)·····1123·2021-01-16·20:24:04.000000·./usr/share/doc/golang-github-julienschmidt-httprouter-dev/changelog.Debian.gz
7 -rw-r--r--···0·root·········(0)·root·········(0)·····1800·2021-01-16·20:24:04.000000·./usr/share/doc/golang-github-julienschmidt-httprouter-dev/copyright7 -rw-r--r--···0·root·········(0)·root·········(0)·····1800·2021-01-16·20:24:04.000000·./usr/share/doc/golang-github-julienschmidt-httprouter-dev/copyright
8 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/8 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/
9 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/src/9 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/src/
10 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/10 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/
11 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/11 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/
12 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/12 drwxr-xr-x···0·root·········(0)·root·········(0)········0·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/
13 -rw-r--r--···0·root·········(0)·root·········(0)·······51·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/go.mod13 -rw-r--r--···0·root·········(0)·root·········(0)·······51·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/go.mod
14 -rw-r--r--···0·root·········(0)·root·········(0)·····2671·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/path.go14 -rw-r--r--···0·root·········(0)·root·········(0)·····3571·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/path.go
15 -rw-r--r--···0·root·········(0)·root·········(0)·····2127·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/path_test.go15 -rw-r--r--···0·root·········(0)·root·········(0)·····3269·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/path_test.go
16 -rw-r--r--···0·root·········(0)·root·········(0)····14900·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/router.go16 -rw-r--r--···0·root·········(0)·root·········(0)····17147·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/router.go
17 -rw-r--r--···0·root·········(0)·root·········(0)····16292·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/router_test.go17 -rw-r--r--···0·root·········(0)·root·········(0)····18984·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/router_test.go
18 -rw-r--r--···0·root·········(0)·root·········(0)····16649·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/tree.go18 -rw-r--r--···0·root·········(0)·root·········(0)····16645·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/tree.go
19 -rw-r--r--···0·root·········(0)·root·········(0)····17047·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/tree_test.go19 -rw-r--r--···0·root·········(0)·root·········(0)····16823·2021-01-16·20:24:04.000000·./usr/share/gocode/src/github.com/julienschmidt/httprouter/tree_test.go
792 B
./usr/share/doc/golang-github-julienschmidt-httprouter-dev/changelog.Debian.gz
636 B
changelog.Debian
    
Offset 1, 12 lines modifiedOffset 1, 13 lines modified
1 golang-github-julienschmidt-httprouter·(1.3.0-1~jan+unchanged1)·unchanged;·urgency=low1 golang-github-julienschmidt-httprouter·(1.3.0+git20200921.1.fe77dd0-1~jan+nus1)·fresh-snapshots;·urgency=low
  
 2 ··*·New·upstream·snapshot.
2 ··*·Build·for·debian-janitor·apt·repository.3 ··*·Build·for·debian-janitor·apt·repository.
  
3 ·--·Debian·Janitor·<janitor@jelmer.uk>··Fri,·09·Apr·2021·23:44:19·-00004 ·--·Debian·Janitor·<janitor@jelmer.uk>··Fri,·09·Apr·2021·22:02:29·-0000
  
4 golang-github-julienschmidt-httprouter·(1.3.0-1)·unstable;·urgency=medium5 golang-github-julienschmidt-httprouter·(1.3.0-1)·unstable;·urgency=medium
  
5 ··*·Team·upload.6 ··*·Team·upload.
  
6 ··[·Alexandre·Viau·]7 ··[·Alexandre·Viau·]
7 ··*·Point·Vcs-*·urls·to·salsa.debian.org.8 ··*·Point·Vcs-*·urls·to·salsa.debian.org.
3.49 KB
./usr/share/gocode/src/github.com/julienschmidt/httprouter/path.go
    
Offset 15, 41 lines modifiedOffset 15, 52 lines modified
15 //»     3.·Eliminate·each·inner·..·path·name·element·(the·parent·directory)15 //»     3.·Eliminate·each·inner·..·path·name·element·(the·parent·directory)
16 //»     ···along·with·the·non-..·element·that·precedes·it.16 //»     ···along·with·the·non-..·element·that·precedes·it.
17 //»     4.·Eliminate·..·elements·that·begin·a·rooted·path:17 //»     4.·Eliminate·..·elements·that·begin·a·rooted·path:
18 //»     ···that·is,·replace·"/.."·by·"/"·at·the·beginning·of·a·path.18 //»     ···that·is,·replace·"/.."·by·"/"·at·the·beginning·of·a·path.
19 //19 //
20 //·If·the·result·of·this·process·is·an·empty·string,·"/"·is·returned20 //·If·the·result·of·this·process·is·an·empty·string,·"/"·is·returned
21 func·CleanPath(p·string)·string·{21 func·CleanPath(p·string)·string·{
 22 »       const·stackBufSize·=·128
  
22 »       //·Turn·empty·string·into·"/"23 »       //·Turn·empty·string·into·"/"
23 »       if·p·==·""·{24 »       if·p·==·""·{
24 »       »       return·"/"25 »       »       return·"/"
25 »       }26 »       }
  
 27 »       //·Reasonably·sized·buffer·on·stack·to·avoid·allocations·in·the·common·case.
 28 »       //·If·a·larger·buffer·is·required,·it·gets·allocated·dynamically.
 29 »       buf·:=·make([]byte,·0,·stackBufSize)
  
26 »       n·:=·len(p)30 »       n·:=·len(p)
27 »       var·buf·[]byte 
  
28 »       //·Invariants:31 »       //·Invariants:
29 »       //······reading·from·path;·r·is·index·of·next·byte·to·process.32 »       //······reading·from·path;·r·is·index·of·next·byte·to·process.
30 »       //······writing·to·buf;·w·is·index·of·next·byte·to·write.33 »       //······writing·to·buf;·w·is·index·of·next·byte·to·write.
  
31 »       //·path·must·start·with·'/'34 »       //·path·must·start·with·'/'
32 »       r·:=·135 »       r·:=·1
33 »       w·:=·136 »       w·:=·1
  
34 »       if·p[0]·!=·'/'·{37 »       if·p[0]·!=·'/'·{
35 »       »       r·=·038 »       »       r·=·0
  
 39 »       »       if·n+1·>·stackBufSize·{
36 »       »       buf·=·make([]byte,·n+1)40 »       »       »       buf·=·make([]byte,·n+1)
 41 »       »       }·else·{
 42 »       »       »       buf·=·buf[:n+1]
 43 »       »       }
37 »       »       buf[0]·=·'/'44 »       »       buf[0]·=·'/'
38 »       }45 »       }
  
39 »       trailing·:=·n·>·1·&&·p[n-1]·==·'/'46 »       trailing·:=·n·>·1·&&·p[n-1]·==·'/'
  
40 »       //·A·bit·more·clunky·without·a·'lazybuf'·like·the·path·package,·but·the·loop47 »       //·A·bit·more·clunky·without·a·'lazybuf'·like·the·path·package,·but·the·loop
41 »       //·gets·completely·inlined·(bufApp).·So·in·contrast·to·the·path·package·this 
42 »       //·loop·has·no·expensive·function·calls·(except·1x·make)48 »       //·gets·completely·inlined·(bufApp·calls).
 49 »       //·So·in·contrast·to·the·path·package·this·loop·has·no·expensive·function
 50 »       //·calls·(except·make,·if·needed).
  
43 »       for·r·<·n·{51 »       for·r·<·n·{
44 »       »       switch·{52 »       »       switch·{
45 »       »       case·p[r]·==·'/':53 »       »       case·p[r]·==·'/':
46 »       »       »       //·empty·path·element,·trailing·slash·is·added·after·the·end54 »       »       »       //·empty·path·element,·trailing·slash·is·added·after·the·end
47 »       »       »       r++55 »       »       »       r++
  
Offset 65, 59 lines modifiedOffset 76, 75 lines modified
65 »       »       »       //·..·element:·remove·to·last·/76 »       »       »       //·..·element:·remove·to·last·/
66 »       »       »       r·+=·377 »       »       »       r·+=·3
  
67 »       »       »       if·w·>·1·{78 »       »       »       if·w·>·1·{
68 »       »       »       »       //·can·backtrack79 »       »       »       »       //·can·backtrack
69 »       »       »       »       w--80 »       »       »       »       w--
  
70 »       »       »       »       if·buf·==·nil·{81 »       »       »       »       if·len(buf)·==·0·{
71 »       »       »       »       »       for·w·>·1·&&·p[w]·!=·'/'·{82 »       »       »       »       »       for·w·>·1·&&·p[w]·!=·'/'·{
72 »       »       »       »       »       »       w--83 »       »       »       »       »       »       w--
73 »       »       »       »       »       }84 »       »       »       »       »       }
74 »       »       »       »       }·else·{85 »       »       »       »       }·else·{
75 »       »       »       »       »       for·w·>·1·&&·buf[w]·!=·'/'·{86 »       »       »       »       »       for·w·>·1·&&·buf[w]·!=·'/'·{
76 »       »       »       »       »       »       w--87 »       »       »       »       »       »       w--
77 »       »       »       »       »       }88 »       »       »       »       »       }
78 »       »       »       »       }89 »       »       »       »       }
79 »       »       »       }90 »       »       »       }
  
80 »       »       default:91 »       »       default:
81 »       »       »       //·real·path·element.92 »       »       »       //·Real·path·element.
82 »       »       »       //·add·slash·if·needed93 »       »       »       //·Add·slash·if·needed
83 »       »       »       if·w·>·1·{94 »       »       »       if·w·>·1·{
84 »       »       »       »       bufApp(&buf,·p,·w,·'/')95 »       »       »       »       bufApp(&buf,·p,·w,·'/')
85 »       »       »       »       w++96 »       »       »       »       w++
86 »       »       »       }97 »       »       »       }
  
87 »       »       »       //·copy·element98 »       »       »       //·Copy·element
88 »       »       »       for·r·<·n·&&·p[r]·!=·'/'·{99 »       »       »       for·r·<·n·&&·p[r]·!=·'/'·{
89 »       »       »       »       bufApp(&buf,·p,·w,·p[r])100 »       »       »       »       bufApp(&buf,·p,·w,·p[r])
90 »       »       »       »       w++101 »       »       »       »       w++
91 »       »       »       »       r++102 »       »       »       »       r++
92 »       »       »       }103 »       »       »       }
93 »       »       }104 »       »       }
94 »       }105 »       }
  
95 »       //·re-append·trailing·slash106 »       //·Re-append·trailing·slash
96 »       if·trailing·&&·w·>·1·{107 »       if·trailing·&&·w·>·1·{
97 »       »       bufApp(&buf,·p,·w,·'/')108 »       »       bufApp(&buf,·p,·w,·'/')
98 »       »       w++109 »       »       w++
99 »       }110 »       }
  
100 »       if·buf·==·nil·{111 »       //·If·the·original·string·was·not·modified·(or·only·shortened·at·the·end),
 112 »       //·return·the·respective·substring·of·the·original·string.
 113 »       //·Otherwise·return·a·new·string·from·the·buffer.
 114 »       if·len(buf)·==·0·{
101 »       »       return·p[:w]115 »       »       return·p[:w]
102 »       }116 »       }
103 »       return·string(buf[:w])117 »       return·string(buf[:w])
104 }118 }
  
105 //·internal·helper·to·lazily·create·a·buffer·if·necessary119 //·Internal·helper·to·lazily·create·a·buffer·if·necessary.
 120 //·Calls·to·this·function·get·inlined.
106 func·bufApp(buf·*[]byte,·s·string,·w·int,·c·byte)·{121 func·bufApp(buf·*[]byte,·s·string,·w·int,·c·byte)·{
107 »       if·*buf·==·nil·{122 »       b·:=·*buf
 123 »       if·len(b)·==·0·{
 124 »       »       //·No·modification·of·the·original·string·so·far.
 125 »       »       //·If·the·next·character·is·the·same·as·in·the·original·string,·we·do
 126 »       »       //·not·yet·have·to·allocate·a·buffer.
108 »       »       if·s[w]·==·c·{127 »       »       if·s[w]·==·c·{
109 »       »       »       return128 »       »       »       return
110 »       »       }129 »       »       }
  
 130 »       »       //·Otherwise·use·either·the·stack·buffer,·if·it·is·large·enough,·or
 131 »       »       //·allocate·a·new·buffer·on·the·heap,·and·copy·all·previous·characters.
 132 »       »       if·l·:=·len(s);·l·>·cap(b)·{
111 »       »       *buf·=·make([]byte,·len(s))133 »       »       »       *buf·=·make([]byte,·len(s))
 134 »       »       }·else·{
 135 »       »       »       *buf·=·(*buf)[:l]
 136 »       »       }
 137 »       »       b·=·*buf
  
112 »       »       copy(*buf,·s[:w])138 »       »       copy(b,·s[:w])
Max diff block lines reached; 30/3444 bytes (0.87%) of diff not shown.
2.33 KB
./usr/share/gocode/src/github.com/julienschmidt/httprouter/path_test.go
    
Offset 2, 21 lines modifiedOffset 2, 23 lines modified
2 //·Based·on·the·path·package,·Copyright·2009·The·Go·Authors.2 //·Based·on·the·path·package,·Copyright·2009·The·Go·Authors.
3 //·Use·of·this·source·code·is·governed·by·a·BSD-style·license·that·can·be·found3 //·Use·of·this·source·code·is·governed·by·a·BSD-style·license·that·can·be·found
4 //·in·the·LICENSE·file.4 //·in·the·LICENSE·file.
  
5 package·httprouter5 package·httprouter
  
6 import·(6 import·(
7 »       "runtime"7 »       "strings"
8 »       "testing"8 »       "testing"
9 )9 )
  
10 var·cleanTests·=·[]struct·{10 type·cleanPathTest·struct·{
11 »       path,·result·string11 »       path,·result·string
12 }{12 }
  
 13 var·cleanTests·=·[]cleanPathTest{
13 »       //·Already·clean14 »       //·Already·clean
14 »       {"/",·"/"},15 »       {"/",·"/"},
15 »       {"/abc",·"/abc"},16 »       {"/abc",·"/abc"},
16 »       {"/a/b/c",·"/a/b/c"},17 »       {"/a/b/c",·"/a/b/c"},
17 »       {"/abc/",·"/abc/"},18 »       {"/abc/",·"/abc/"},
18 »       {"/a/b/c/",·"/a/b/c/"},19 »       {"/a/b/c/",·"/a/b/c/"},
  
Offset 75, 19 lines modifiedOffset 77, 73 lines modified
75 »       }77 »       }
76 }78 }
  
77 func·TestPathCleanMallocs(t·*testing.T)·{79 func·TestPathCleanMallocs(t·*testing.T)·{
78 »       if·testing.Short()·{80 »       if·testing.Short()·{
79 »       »       t.Skip("skipping·malloc·count·in·short·mode")81 »       »       t.Skip("skipping·malloc·count·in·short·mode")
80 »       }82 »       }
81 »       if·runtime.GOMAXPROCS(0)·>·1·{ 
82 »       »       t.Log("skipping·AllocsPerRun·checks;·GOMAXPROCS>1") 
83 »       »       return 
84 »       } 
  
85 »       for·_,·test·:=·range·cleanTests·{83 »       for·_,·test·:=·range·cleanTests·{
 84 »       »       test·:=·test
86 »       »       allocs·:=·testing.AllocsPerRun(100,·func()·{·CleanPath(test.result)·})85 »       »       allocs·:=·testing.AllocsPerRun(100,·func()·{·CleanPath(test.result)·})
87 »       »       if·allocs·>·0·{86 »       »       if·allocs·>·0·{
88 »       »       »       t.Errorf("CleanPath(%q):·%v·allocs,·want·zero",·test.result,·allocs)87 »       »       »       t.Errorf("CleanPath(%q):·%v·allocs,·want·zero",·test.result,·allocs)
89 »       »       }88 »       »       }
90 »       }89 »       }
91 }90 }
  
 91 func·BenchmarkPathClean(b·*testing.B)·{
 92 »       b.ReportAllocs()
  
 93 »       for·i·:=·0;·i·<·b.N;·i++·{
 94 »       »       for·_,·test·:=·range·cleanTests·{
 95 »       »       »       CleanPath(test.path)
 96 »       »       }
 97 »       }
 98 }
  
 99 func·genLongPaths()·(testPaths·[]cleanPathTest)·{
 100 »       for·i·:=·1;·i·<=·1234;·i++·{
 101 »       »       ss·:=·strings.Repeat("a",·i)
  
 102 »       »       correctPath·:=·"/"·+·ss
 103 »       »       testPaths·=·append(testPaths,·cleanPathTest{
 104 »       »       »       path:···correctPath,
 105 »       »       »       result:·correctPath,
 106 »       »       },·cleanPathTest{
 107 »       »       »       path:···ss,
 108 »       »       »       result:·correctPath,
 109 »       »       },·cleanPathTest{
 110 »       »       »       path:···"//"·+·ss,
 111 »       »       »       result:·correctPath,
 112 »       »       },·cleanPathTest{
 113 »       »       »       path:···"/"·+·ss·+·"/b/..",
 114 »       »       »       result:·correctPath,
 115 »       »       })
 116 »       }
 117 »       return·testPaths
 118 }
  
 119 func·TestPathCleanLong(t·*testing.T)·{
 120 »       cleanTests·:=·genLongPaths()
  
 121 »       for·_,·test·:=·range·cleanTests·{
 122 »       »       if·s·:=·CleanPath(test.path);·s·!=·test.result·{
 123 »       »       »       t.Errorf("CleanPath(%q)·=·%q,·want·%q",·test.path,·s,·test.result)
 124 »       »       }
 125 »       »       if·s·:=·CleanPath(test.result);·s·!=·test.result·{
 126 »       »       »       t.Errorf("CleanPath(%q)·=·%q,·want·%q",·test.result,·s,·test.result)
 127 »       »       }
 128 »       }
 129 }
  
 130 func·BenchmarkPathCleanLong(b·*testing.B)·{
 131 »       cleanTests·:=·genLongPaths()
 132 »       b.ResetTimer()
 133 »       b.ReportAllocs()
  
 134 »       for·i·:=·0;·i·<·b.N;·i++·{
 135 »       »       for·_,·test·:=·range·cleanTests·{
 136 »       »       »       CleanPath(test.path)
 137 »       »       }
 138 »       }
 139 }
10.0 KB
./usr/share/gocode/src/github.com/julienschmidt/httprouter/router.go
    
Offset 30, 15 lines modifiedOffset 30, 15 lines modified
30 //30 //
31 //······log.Fatal(http.ListenAndServe(":8080",·router))31 //······log.Fatal(http.ListenAndServe(":8080",·router))
32 //··}32 //··}
33 //33 //
34 //·The·router·matches·incoming·requests·by·the·request·method·and·the·path.34 //·The·router·matches·incoming·requests·by·the·request·method·and·the·path.
35 //·If·a·handle·is·registered·for·this·path·and·method,·the·router·delegates·the35 //·If·a·handle·is·registered·for·this·path·and·method,·the·router·delegates·the
36 //·request·to·that·function.36 //·request·to·that·function.
37 //·For·the·methods·GET,·POST,·PUT,·PATCH·and·DELETE·shortcut·functions·exist·to37 //·For·the·methods·GET,·POST,·PUT,·PATCH,·DELETE·and·OPTIONS·shortcut·functions·exist·to
38 //·register·handles,·for·all·other·methods·router.Handle·can·be·used.38 //·register·handles,·for·all·other·methods·router.Handle·can·be·used.
39 //39 //
40 //·The·registered·path,·against·which·the·router·matches·incoming·requests,·can40 //·The·registered·path,·against·which·the·router·matches·incoming·requests,·can
41 //·contain·two·types·of·parameters:41 //·contain·two·types·of·parameters:
42 //··Syntax····Type42 //··Syntax····Type
43 //··:name·····named·parameter43 //··:name·····named·parameter
44 //··*name·····catch-all·parameter44 //··*name·····catch-all·parameter
Offset 76, 19 lines modifiedOffset 76, 20 lines modified
76 //··thirdValue·:=·ps[2].Value·//·the·value·of·the·3rd·parameter76 //··thirdValue·:=·ps[2].Value·//·the·value·of·the·3rd·parameter
77 package·httprouter77 package·httprouter
  
78 import·(78 import·(
79 »       "context"79 »       "context"
80 »       "net/http"80 »       "net/http"
81 »       "strings"81 »       "strings"
 82 »       "sync"
82 )83 )
  
83 //·Handle·is·a·function·that·can·be·registered·to·a·route·to·handle·HTTP84 //·Handle·is·a·function·that·can·be·registered·to·a·route·to·handle·HTTP
84 //·requests.·Like·http.HandlerFunc,·but·has·a·third·parameter·for·the·values·of85 //·requests.·Like·http.HandlerFunc,·but·has·a·third·parameter·for·the·values·of
85 //·wildcards·(variables).86 //·wildcards·(path·variables).
86 type·Handle·func(http.ResponseWriter,·*http.Request,·Params)87 type·Handle·func(http.ResponseWriter,·*http.Request,·Params)
  
87 //·Param·is·a·single·URL·parameter,·consisting·of·a·key·and·a·value.88 //·Param·is·a·single·URL·parameter,·consisting·of·a·key·and·a·value.
88 type·Param·struct·{89 type·Param·struct·{
89 »       Key···string90 »       Key···string
90 »       Value·string91 »       Value·string
91 }92 }
Offset 97, 17 lines modifiedOffset 98, 17 lines modified
97 //·The·slice·is·ordered,·the·first·URL·parameter·is·also·the·first·slice·value.98 //·The·slice·is·ordered,·the·first·URL·parameter·is·also·the·first·slice·value.
98 //·It·is·therefore·safe·to·read·values·by·the·index.99 //·It·is·therefore·safe·to·read·values·by·the·index.
99 type·Params·[]Param100 type·Params·[]Param
  
100 //·ByName·returns·the·value·of·the·first·Param·which·key·matches·the·given·name.101 //·ByName·returns·the·value·of·the·first·Param·which·key·matches·the·given·name.
101 //·If·no·matching·Param·is·found,·an·empty·string·is·returned.102 //·If·no·matching·Param·is·found,·an·empty·string·is·returned.
102 func·(ps·Params)·ByName(name·string)·string·{103 func·(ps·Params)·ByName(name·string)·string·{
103 »       for·i·:=·range·ps·{104 »       for·_,·p·:=·range·ps·{
104 »       »       if·ps[i].Key·==·name·{105 »       »       if·p.Key·==·name·{
105 »       »       »       return·ps[i].Value106 »       »       »       return·p.Value
106 »       »       }107 »       »       }
107 »       }108 »       }
108 »       return·""109 »       return·""
109 }110 }
  
110 type·paramsKey·struct{}111 type·paramsKey·struct{}
  
Offset 117, 32 lines modifiedOffset 118, 52 lines modified
117 //·ParamsFromContext·pulls·the·URL·parameters·from·a·request·context,118 //·ParamsFromContext·pulls·the·URL·parameters·from·a·request·context,
118 //·or·returns·nil·if·none·are·present.119 //·or·returns·nil·if·none·are·present.
119 func·ParamsFromContext(ctx·context.Context)·Params·{120 func·ParamsFromContext(ctx·context.Context)·Params·{
120 »       p,·_·:=·ctx.Value(ParamsKey).(Params)121 »       p,·_·:=·ctx.Value(ParamsKey).(Params)
121 »       return·p122 »       return·p
122 }123 }
  
 124 //·MatchedRoutePathParam·is·the·Param·name·under·which·the·path·of·the·matched
 125 //·route·is·stored,·if·Router.SaveMatchedRoutePath·is·set.
 126 var·MatchedRoutePathParam·=·"$matchedRoutePath"
  
 127 //·MatchedRoutePath·retrieves·the·path·of·the·matched·route.
 128 //·Router.SaveMatchedRoutePath·must·have·been·enabled·when·the·respective
 129 //·handler·was·added,·otherwise·this·function·always·returns·an·empty·string.
 130 func·(ps·Params)·MatchedRoutePath()·string·{
 131 »       return·ps.ByName(MatchedRoutePathParam)
 132 }
  
123 //·Router·is·a·http.Handler·which·can·be·used·to·dispatch·requests·to·different133 //·Router·is·a·http.Handler·which·can·be·used·to·dispatch·requests·to·different
124 //·handler·functions·via·configurable·routes134 //·handler·functions·via·configurable·routes
125 type·Router·struct·{135 type·Router·struct·{
126 »       trees·map[string]*node136 »       trees·map[string]*node
  
 137 »       paramsPool·sync.Pool
 138 »       maxParams··uint16
  
 139 »       //·If·enabled,·adds·the·matched·route·path·onto·the·http.Request·context
 140 »       //·before·invoking·the·handler.
 141 »       //·The·matched·route·path·is·only·added·to·handlers·of·routes·that·were
 142 »       //·registered·when·this·option·was·enabled.
 143 »       SaveMatchedRoutePath·bool
  
127 »       //·Enables·automatic·redirection·if·the·current·route·can't·be·matched·but·a144 »       //·Enables·automatic·redirection·if·the·current·route·can't·be·matched·but·a
128 »       //·handler·for·the·path·with·(without)·the·trailing·slash·exists.145 »       //·handler·for·the·path·with·(without)·the·trailing·slash·exists.
129 »       //·For·example·if·/foo/·is·requested·but·a·route·only·exists·for·/foo,·the146 »       //·For·example·if·/foo/·is·requested·but·a·route·only·exists·for·/foo,·the
130 »       //·client·is·redirected·to·/foo·with·http·status·code·301·for·GET·requests147 »       //·client·is·redirected·to·/foo·with·http·status·code·301·for·GET·requests
131 »       //·and·307·for·all·other·request·methods.148 »       //·and·308·for·all·other·request·methods.
132 »       RedirectTrailingSlash·bool149 »       RedirectTrailingSlash·bool
  
133 »       //·If·enabled,·the·router·tries·to·fix·the·current·request·path,·if·no150 »       //·If·enabled,·the·router·tries·to·fix·the·current·request·path,·if·no
134 »       //·handle·is·registered·for·it.151 »       //·handle·is·registered·for·it.
135 »       //·First·superfluous·path·elements·like·../·or·//·are·removed.152 »       //·First·superfluous·path·elements·like·../·or·//·are·removed.
136 »       //·Afterwards·the·router·does·a·case-insensitive·lookup·of·the·cleaned·path.153 »       //·Afterwards·the·router·does·a·case-insensitive·lookup·of·the·cleaned·path.
137 »       //·If·a·handle·can·be·found·for·this·route,·the·router·makes·a·redirection154 »       //·If·a·handle·can·be·found·for·this·route,·the·router·makes·a·redirection
138 »       //·to·the·corrected·path·with·status·code·301·for·GET·requests·and·307·for155 »       //·to·the·corrected·path·with·status·code·301·for·GET·requests·and·308·for
139 »       //·all·other·request·methods.156 »       //·all·other·request·methods.
140 »       //·For·example·/FOO·and·/..//Foo·could·be·redirected·to·/foo.157 »       //·For·example·/FOO·and·/..//Foo·could·be·redirected·to·/foo.
141 »       //·RedirectTrailingSlash·is·independent·of·this·option.158 »       //·RedirectTrailingSlash·is·independent·of·this·option.
142 »       RedirectFixedPath·bool159 »       RedirectFixedPath·bool
  
143 »       //·If·enabled,·the·router·checks·if·another·method·is·allowed·for·the160 »       //·If·enabled,·the·router·checks·if·another·method·is·allowed·for·the
144 »       //·current·route,·if·the·current·request·can·not·be·routed.161 »       //·current·route,·if·the·current·request·can·not·be·routed.
Offset 194, 14 lines modifiedOffset 215, 41 lines modified
194 »       »       RedirectTrailingSlash:··true,215 »       »       RedirectTrailingSlash:··true,
195 »       »       RedirectFixedPath:······true,216 »       »       RedirectFixedPath:······true,
196 »       »       HandleMethodNotAllowed:·true,217 »       »       HandleMethodNotAllowed:·true,
197 »       »       HandleOPTIONS:··········true,218 »       »       HandleOPTIONS:··········true,
198 »       }219 »       }
199 }220 }
  
 221 func·(r·*Router)·getParams()·*Params·{
 222 »       ps,·_·:=·r.paramsPool.Get().(*Params)
 223 »       *ps·=·(*ps)[0:0]·//·reset·slice
 224 »       return·ps
 225 }
  
 226 func·(r·*Router)·putParams(ps·*Params)·{
 227 »       if·ps·!=·nil·{
 228 »       »       r.paramsPool.Put(ps)
 229 »       }
 230 }
  
Max diff block lines reached; 4929/10115 bytes (48.73%) of diff not shown.
7.25 KB
./usr/share/gocode/src/github.com/julienschmidt/httprouter/router_test.go
    
Offset 160, 22 lines modifiedOffset 160, 46 lines modified
160 »       r,·_·=·http.NewRequest(http.MethodGet,·"/HandlerFunc",·nil)160 »       r,·_·=·http.NewRequest(http.MethodGet,·"/HandlerFunc",·nil)
161 »       router.ServeHTTP(w,·r)161 »       router.ServeHTTP(w,·r)
162 »       if·!handlerFunc·{162 »       if·!handlerFunc·{
163 »       »       t.Error("routing·HandlerFunc·failed")163 »       »       t.Error("routing·HandlerFunc·failed")
164 »       }164 »       }
165 }165 }
  
166 func·TestRouterRoot(t·*testing.T)·{166 func·TestRouterInvalidInput(t·*testing.T)·{
167 »       router·:=·New()167 »       router·:=·New()
  
 168 »       handle·:=·func(_·http.ResponseWriter,·_·*http.Request,·_·Params)·{}
  
168 »       recv·:=·catchPanic(func()·{169 »       recv·:=·catchPanic(func()·{
 170 »       »       router.Handle("",·"/",·handle)
 171 »       })
 172 »       if·recv·==·nil·{
 173 »       »       t.Fatal("registering·empty·method·did·not·panic")
 174 »       }
  
 175 »       recv·=·catchPanic(func()·{
 176 »       »       router.GET("",·handle)
 177 »       })
 178 »       if·recv·==·nil·{
 179 »       »       t.Fatal("registering·empty·path·did·not·panic")
 180 »       }
  
 181 »       recv·=·catchPanic(func()·{
169 »       »       router.GET("noSlashRoot",·nil)182 »       »       router.GET("noSlashRoot",·handle)
170 »       })183 »       })
171 »       if·recv·==·nil·{184 »       if·recv·==·nil·{
172 »       »       t.Fatal("registering·path·not·beginning·with·'/'·did·not·panic")185 »       »       t.Fatal("registering·path·not·beginning·with·'/'·did·not·panic")
173 »       }186 »       }
  
 187 »       recv·=·catchPanic(func()·{
 188 »       »       router.GET("/",·nil)
 189 »       })
 190 »       if·recv·==·nil·{
 191 »       »       t.Fatal("registering·nil·handler·did·not·panic")
 192 »       }
174 }193 }
  
175 func·TestRouterChaining(t·*testing.T)·{194 func·TestRouterChaining(t·*testing.T)·{
176 »       router1·:=·New()195 »       router1·:=·New()
177 »       router2·:=·New()196 »       router2·:=·New()
178 »       router1.NotFound·=·router2197 »       router1.NotFound·=·router2
  
Offset 391, 62 lines modifiedOffset 415, 62 lines modified
391 »       router.GET("/",·handlerFunc)415 »       router.GET("/",·handlerFunc)
  
392 »       testRoutes·:=·[]struct·{416 »       testRoutes·:=·[]struct·{
393 »       »       route····string417 »       »       route····string
394 »       »       code·····int418 »       »       code·····int
395 »       »       location·string419 »       »       location·string
396 »       }{420 »       }{
397 »       »       {"/path/",·301,·"/path"},···//·TSR·-/ 
398 »       »       {"/dir",·301,·"/dir/"},·····//·TSR·+/ 
399 »       »       {"",·301,·"/"},·············//·TSR·+/ 
400 »       »       {"/PATH",·301,·"/path"},····//·Fixed·Case 
401 »       »       {"/DIR/",·301,·"/dir/"},····//·Fixed·Case 
402 »       »       {"/PATH/",·301,·"/path"},···//·Fixed·Case·-/ 
403 »       »       {"/DIR",·301,·"/dir/"},·····//·Fixed·Case·+/ 
404 »       »       {"/../path",·301,·"/path"},·//·CleanPath 
405 »       »       {"/nope",·404,·""},·········//·NotFound421 »       »       {"/path/",·http.StatusMovedPermanently,·"/path"},···//·TSR·-/
 422 »       »       {"/dir",·http.StatusMovedPermanently,·"/dir/"},·····//·TSR·+/
 423 »       »       {"",·http.StatusMovedPermanently,·"/"},·············//·TSR·+/
 424 »       »       {"/PATH",·http.StatusMovedPermanently,·"/path"},····//·Fixed·Case
 425 »       »       {"/DIR/",·http.StatusMovedPermanently,·"/dir/"},····//·Fixed·Case
 426 »       »       {"/PATH/",·http.StatusMovedPermanently,·"/path"},···//·Fixed·Case·-/
 427 »       »       {"/DIR",·http.StatusMovedPermanently,·"/dir/"},·····//·Fixed·Case·+/
 428 »       »       {"/../path",·http.StatusMovedPermanently,·"/path"},·//·CleanPath
 429 »       »       {"/nope",·http.StatusNotFound,·""},·················//·NotFound
406 »       }430 »       }
407 »       for·_,·tr·:=·range·testRoutes·{431 »       for·_,·tr·:=·range·testRoutes·{
408 »       »       r,·_·:=·http.NewRequest(http.MethodGet,·tr.route,·nil)432 »       »       r,·_·:=·http.NewRequest(http.MethodGet,·tr.route,·nil)
409 »       »       w·:=·httptest.NewRecorder()433 »       »       w·:=·httptest.NewRecorder()
410 »       »       router.ServeHTTP(w,·r)434 »       »       router.ServeHTTP(w,·r)
411 »       »       if·!(w.Code·==·tr.code·&&·(w.Code·==·404·||·fmt.Sprint(w.Header().Get("Location"))·==·tr.location))·{435 »       »       if·!(w.Code·==·tr.code·&&·(w.Code·==·http.StatusNotFound·||·fmt.Sprint(w.Header().Get("Location"))·==·tr.location))·{
412 »       »       »       t.Errorf("NotFound·handling·route·%s·failed:·Code=%d,·Header=%v",·tr.route,·w.Code,·w.Header().Get("Location"))436 »       »       »       t.Errorf("NotFound·handling·route·%s·failed:·Code=%d,·Header=%v",·tr.route,·w.Code,·w.Header().Get("Location"))
413 »       »       }437 »       »       }
414 »       }438 »       }
  
415 »       //·Test·custom·not·found·handler439 »       //·Test·custom·not·found·handler
416 »       var·notFound·bool440 »       var·notFound·bool
417 »       router.NotFound·=·http.HandlerFunc(func(rw·http.ResponseWriter,·r·*http.Request)·{441 »       router.NotFound·=·http.HandlerFunc(func(rw·http.ResponseWriter,·r·*http.Request)·{
418 »       »       rw.WriteHeader(404)442 »       »       rw.WriteHeader(http.StatusNotFound)
419 »       »       notFound·=·true443 »       »       notFound·=·true
420 »       })444 »       })
421 »       r,·_·:=·http.NewRequest(http.MethodGet,·"/nope",·nil)445 »       r,·_·:=·http.NewRequest(http.MethodGet,·"/nope",·nil)
422 »       w·:=·httptest.NewRecorder()446 »       w·:=·httptest.NewRecorder()
423 »       router.ServeHTTP(w,·r)447 »       router.ServeHTTP(w,·r)
424 »       if·!(w.Code·==·404·&&·notFound·==·true)·{448 »       if·!(w.Code·==·http.StatusNotFound·&&·notFound·==·true)·{
425 »       »       t.Errorf("Custom·NotFound·handler·failed:·Code=%d,·Header=%v",·w.Code,·w.Header())449 »       »       t.Errorf("Custom·NotFound·handler·failed:·Code=%d,·Header=%v",·w.Code,·w.Header())
426 »       }450 »       }
  
427 »       //·Test·other·method·than·GET·(want·307·instead·of·301)451 »       //·Test·other·method·than·GET·(want·308·instead·of·301)
428 »       router.PATCH("/path",·handlerFunc)452 »       router.PATCH("/path",·handlerFunc)
429 »       r,·_·=·http.NewRequest(http.MethodPatch,·"/path/",·nil)453 »       r,·_·=·http.NewRequest(http.MethodPatch,·"/path/",·nil)
430 »       w·=·httptest.NewRecorder()454 »       w·=·httptest.NewRecorder()
431 »       router.ServeHTTP(w,·r)455 »       router.ServeHTTP(w,·r)
432 »       if·!(w.Code·==·307·&&·fmt.Sprint(w.Header())·==·"map[Location:[/path]]")·{456 »       if·!(w.Code·==·http.StatusPermanentRedirect·&&·fmt.Sprint(w.Header())·==·"map[Location:[/path]]")·{
433 »       »       t.Errorf("Custom·NotFound·handler·failed:·Code=%d,·Header=%v",·w.Code,·w.Header())457 »       »       t.Errorf("Custom·NotFound·handler·failed:·Code=%d,·Header=%v",·w.Code,·w.Header())
434 »       }458 »       }
  
435 »       //·Test·special·case·where·no·node·for·the·prefix·"/"·exists459 »       //·Test·special·case·where·no·node·for·the·prefix·"/"·exists
436 »       router·=·New()460 »       router·=·New()
437 »       router.GET("/a",·handlerFunc)461 »       router.GET("/a",·handlerFunc)
438 »       r,·_·=·http.NewRequest(http.MethodGet,·"/",·nil)462 »       r,·_·=·http.NewRequest(http.MethodGet,·"/",·nil)
439 »       w·=·httptest.NewRecorder()463 »       w·=·httptest.NewRecorder()
440 »       router.ServeHTTP(w,·r)464 »       router.ServeHTTP(w,·r)
441 »       if·!(w.Code·==·404)·{465 »       if·!(w.Code·==·http.StatusNotFound)·{
442 »       »       t.Errorf("NotFound·handling·route·/·failed:·Code=%d",·w.Code)466 »       »       t.Errorf("NotFound·handling·route·/·failed:·Code=%d",·w.Code)
443 »       }467 »       }
444 }468 }
  
445 func·TestRouterPanicHandler(t·*testing.T)·{469 func·TestRouterPanicHandler(t·*testing.T)·{
446 »       router·:=·New()470 »       router·:=·New()
447 »       panicHandled·:=·false471 »       panicHandled·:=·false
Offset 491, 28 lines modifiedOffset 515, 42 lines modified
491 »       }515 »       }
492 »       if·tsr·{516 »       if·tsr·{
493 »       »       t.Error("Got·wrong·TSR·recommendation!")517 »       »       t.Error("Got·wrong·TSR·recommendation!")
494 »       }518 »       }
  
495 »       //·insert·route·and·try·again519 »       //·insert·route·and·try·again
496 »       router.GET("/user/:name",·wantHandle)520 »       router.GET("/user/:name",·wantHandle)
  
497 »       handle,·params,·_·:=·router.Lookup(http.MethodGet,·"/user/gopher")521 »       handle,·params,·_·:=·router.Lookup(http.MethodGet,·"/user/gopher")
Max diff block lines reached; 2783/7282 bytes (38.22%) of diff not shown.
26.8 KB
./usr/share/gocode/src/github.com/julienschmidt/httprouter/tree.go
    
Offset 13, 380 lines modifiedOffset 13, 372 lines modified
13 func·min(a,·b·int)·int·{13 func·min(a,·b·int)·int·{
14 »       if·a·<=·b·{14 »       if·a·<=·b·{
15 »       »       return·a15 »       »       return·a
16 »       }16 »       }
17 »       return·b17 »       return·b
18 }18 }
  
19 const·maxParamCount·uint8·=·^uint8(0)19 func·longestCommonPrefix(a,·b·string)·int·{
 20 »       i·:=·0
 21 »       max·:=·min(len(a),·len(b))
 22 »       for·i·<·max·&&·a[i]·==·b[i]·{
 23 »       »       i++
 24 »       }
 25 »       return·i
 26 }
  
20 func·countParams(path·string)·uint8·{ 
21 »       var·n·uint 
22 »       for·i·:=·0;·i·<·len(path);·i++·{27 //·Search·for·a·wildcard·segment·and·check·the·name·for·invalid·characters.
 28 //·Returns·-1·as·index,·if·no·wildcard·was·found.
 29 func·findWildcard(path·string)·(wilcard·string,·i·int,·valid·bool)·{
 30 »       //·Find·start
 31 »       for·start,·c·:=·range·[]byte(path)·{
 32 »       »       //·A·wildcard·starts·with·':'·(param)·or·'*'·(catch-all)
23 »       »       if·path[i]·!=·':'·&&·path[i]·!=·'*'·{33 »       »       if·c·!=·':'·&&·c·!=·'*'·{
24 »       »       »       continue34 »       »       »       continue
25 »       »       }35 »       »       }
26 »       »       n++ 
 36 »       »       //·Find·end·and·check·for·invalid·characters
 37 »       »       valid·=·true
 38 »       »       for·end,·c·:=·range·[]byte(path[start+1:])·{
 39 »       »       »       switch·c·{
 40 »       »       »       case·'/':
 41 »       »       »       »       return·path[start·:·start+1+end],·start,·valid
 42 »       »       »       case·':',·'*':
 43 »       »       »       »       valid·=·false
 44 »       »       »       }
27 »       }45 »       »       }
 46 »       »       return·path[start:],·start,·valid
28 »       if·n·>=·uint(maxParamCount)·{ 
29 »       »       return·maxParamCount 
30 »       }47 »       }
 48 »       return·"",·-1,·false
 49 }
  
 50 func·countParams(path·string)·uint16·{
 51 »       var·n·uint
 52 »       for·i·:=·range·[]byte(path)·{
 53 »       »       switch·path[i]·{
 54 »       »       case·':',·'*':
 55 »       »       »       n++
 56 »       »       }
 57 »       }
31 »       return·uint8(n)58 »       return·uint16(n)
32 }59 }
  
33 type·nodeType·uint860 type·nodeType·uint8
  
34 const·(61 const·(
35 »       static·nodeType·=·iota·//·default62 »       static·nodeType·=·iota·//·default
36 »       root63 »       root
37 »       param64 »       param
38 »       catchAll65 »       catchAll
39 )66 )
  
40 type·node·struct·{67 type·node·struct·{
41 »       path······string68 »       path······string
 69 »       indices···string
42 »       wildChild·bool70 »       wildChild·bool
43 »       nType·····nodeType71 »       nType·····nodeType
44 »       maxParams·uint8 
45 »       priority··uint3272 »       priority··uint32
46 »       indices···string 
47 »       children··[]*node73 »       children··[]*node
48 »       handle····Handle74 »       handle····Handle
49 }75 }
  
50 //·increments·priority·of·the·given·child·and·reorders·if·necessary76 //·Increments·priority·of·the·given·child·and·reorders·if·necessary
51 func·(n·*node)·incrementChildPrio(pos·int)·int·{77 func·(n·*node)·incrementChildPrio(pos·int)·int·{
 78 »       cs·:=·n.children
52 »       n.children[pos].priority++79 »       cs[pos].priority++
53 »       prio·:=·n.children[pos].priority80 »       prio·:=·cs[pos].priority
  
54 »       //·adjust·position·(move·to·front)81 »       //·Adjust·position·(move·to·front)
55 »       newPos·:=·pos82 »       newPos·:=·pos
56 »       for·newPos·>·0·&&·n.children[newPos-1].priority·<·prio·{83 »       for·;·newPos·>·0·&&·cs[newPos-1].priority·<·prio;·newPos--·{
57 »       »       //·swap·node·positions84 »       »       //·Swap·node·positions
 85 »       »       cs[newPos-1],·cs[newPos]·=·cs[newPos],·cs[newPos-1]
58 »       »       n.children[newPos-1],·n.children[newPos]·=·n.children[newPos],·n.children[newPos-1] 
  
59 »       »       newPos-- 
60 »       }86 »       }
  
61 »       //·build·new·index·char·string87 »       //·Build·new·index·char·string
62 »       if·newPos·!=·pos·{88 »       if·newPos·!=·pos·{
63 »       »       n.indices·=·n.indices[:newPos]·+·//·unchanged·prefix,·might·be·empty89 »       »       n.indices·=·n.indices[:newPos]·+·//·Unchanged·prefix,·might·be·empty
64 »       »       »       n.indices[pos:pos+1]·+·//·the·index·char·we·move90 »       »       »       n.indices[pos:pos+1]·+·//·The·index·char·we·move
65 »       »       »       n.indices[newPos:pos]·+·n.indices[pos+1:]·//·rest·without·char·at·'pos'91 »       »       »       n.indices[newPos:pos]·+·n.indices[pos+1:]·//·Rest·without·char·at·'pos'
66 »       }92 »       }
  
67 »       return·newPos93 »       return·newPos
68 }94 }
  
69 //·addRoute·adds·a·node·with·the·given·handle·to·the·path.95 //·addRoute·adds·a·node·with·the·given·handle·to·the·path.
70 //·Not·concurrency-safe!96 //·Not·concurrency-safe!
71 func·(n·*node)·addRoute(path·string,·handle·Handle)·{97 func·(n·*node)·addRoute(path·string,·handle·Handle)·{
72 »       fullPath·:=·path98 »       fullPath·:=·path
73 »       n.priority++99 »       n.priority++
74 »       numParams·:=·countParams(path) 
  
75 »       //·non-empty·tree100 »       //·Empty·tree
 101 »       if·n.path·==·""·&&·n.indices·==·""·{
 102 »       »       n.insertChild(path,·fullPath,·handle)
 103 »       »       n.nType·=·root
 104 »       »       return
 105 »       }
76 »       if·len(n.path)·>·0·||·len(n.children)·>·0·{ 
77 »       walk: 
78 »       »       for·{ 
79 »       »       »       //·Update·maxParams·of·the·current·node 
80 »       »       »       if·numParams·>·n.maxParams·{ 
81 »       »       »       »       n.maxParams·=·numParams 
82 »       »       »       } 
  
83 »       »       »       //·Find·the·longest·common·prefix. 
84 »       »       »       //·This·also·implies·that·the·common·prefix·contains·no·':'·or·'*' 
85 »       »       »       //·since·the·existing·key·can't·contain·those·chars. 
Max diff block lines reached; 22924/27314 bytes (83.93%) of diff not shown.
14.3 KB
./usr/share/gocode/src/github.com/julienschmidt/httprouter/tree_test.go
    
Offset 9, 23 lines modifiedOffset 9, 23 lines modified
9 »       "net/http"9 »       "net/http"
10 »       "reflect"10 »       "reflect"
11 »       "regexp"11 »       "regexp"
12 »       "strings"12 »       "strings"
13 »       "testing"13 »       "testing"
14 )14 )
  
15 func·printChildren(n·*node,·prefix·string)·{15 //·func·printChildren(n·*node,·prefix·string)·{
16 »       fmt.Printf("·%02d:%02d·%s%s[%d]·%v·%t·%d·\r\n",·n.priority,·n.maxParams,·prefix,·n.path,·len(n.children),·n.handle,·n.wildChild,·n.nType)16 //·»     fmt.Printf("·%02d·%s%s[%d]·%v·%t·%d·\r\n",·n.priority,·prefix,·n.path,·len(n.children),·n.handle,·n.wildChild,·n.nType)
17 »       for·l·:=·len(n.path);·l·>·0;·l--·{17 //·»     for·l·:=·len(n.path);·l·>·0;·l--·{
18 »       »       prefix·+=·"·"18 //·»     »     prefix·+=·"·"
19 »       }19 //·»     }
20 »       for·_,·child·:=·range·n.children·{20 //·»     for·_,·child·:=·range·n.children·{
21 »       »       printChildren(child,·prefix)21 //·»     »     printChildren(child,·prefix)
22 »       } 
23 }22 //·»     }
 23 //·}
  
24 //·Used·as·a·workaround·since·we·can't·compare·functions·or·their·addresses24 //·Used·as·a·workaround·since·we·can't·compare·functions·or·their·addresses
25 var·fakeHandlerValue·string25 var·fakeHandlerValue·string
  
26 func·fakeHandler(val·string)·Handle·{26 func·fakeHandler(val·string)·Handle·{
27 »       return·func(http.ResponseWriter,·*http.Request,·Params)·{27 »       return·func(http.ResponseWriter,·*http.Request,·Params)·{
28 »       »       fakeHandlerValue·=·val28 »       »       fakeHandlerValue·=·val
Offset 35, 31 lines modifiedOffset 35, 42 lines modified
35 type·testRequests·[]struct·{35 type·testRequests·[]struct·{
36 »       path·······string36 »       path·······string
37 »       nilHandler·bool37 »       nilHandler·bool
38 »       route······string38 »       route······string
39 »       ps·········Params39 »       ps·········Params
40 }40 }
  
 41 func·getParams()·*Params·{
 42 »       ps·:=·make(Params,·0,·20)
 43 »       return·&ps
 44 }
  
41 func·checkRequests(t·*testing.T,·tree·*node,·requests·testRequests)·{45 func·checkRequests(t·*testing.T,·tree·*node,·requests·testRequests)·{
42 »       for·_,·request·:=·range·requests·{46 »       for·_,·request·:=·range·requests·{
43 »       »       handler,·ps,·_·:=·tree.getValue(request.path)47 »       »       handler,·psp,·_·:=·tree.getValue(request.path,·getParams)
  
 48 »       »       switch·{
44 »       »       if·handler·==·nil·{49 »       »       case·handler·==·nil:
45 »       »       »       if·!request.nilHandler·{50 »       »       »       if·!request.nilHandler·{
46 »       »       »       »       t.Errorf("handle·mismatch·for·route·'%s':·Expected·non-nil·handle",·request.path)51 »       »       »       »       t.Errorf("handle·mismatch·for·route·'%s':·Expected·non-nil·handle",·request.path)
47 »       »       »       }52 »       »       »       }
48 »       »       }·else·if·request.nilHandler·{53 »       »       case·request.nilHandler:
49 »       »       »       t.Errorf("handle·mismatch·for·route·'%s':·Expected·nil·handle",·request.path)54 »       »       »       t.Errorf("handle·mismatch·for·route·'%s':·Expected·nil·handle",·request.path)
50 »       »       }·else·{55 »       »       default:
51 »       »       »       handler(nil,·nil,·nil)56 »       »       »       handler(nil,·nil,·nil)
52 »       »       »       if·fakeHandlerValue·!=·request.route·{57 »       »       »       if·fakeHandlerValue·!=·request.route·{
53 »       »       »       »       t.Errorf("handle·mismatch·for·route·'%s':·Wrong·handle·(%s·!=·%s)",·request.path,·fakeHandlerValue,·request.route)58 »       »       »       »       t.Errorf("handle·mismatch·for·route·'%s':·Wrong·handle·(%s·!=·%s)",·request.path,·fakeHandlerValue,·request.route)
54 »       »       »       }59 »       »       »       }
55 »       »       }60 »       »       }
  
 61 »       »       var·ps·Params
 62 »       »       if·psp·!=·nil·{
 63 »       »       »       ps·=·*psp
 64 »       »       }
  
56 »       »       if·!reflect.DeepEqual(ps,·request.ps)·{65 »       »       if·!reflect.DeepEqual(ps,·request.ps)·{
57 »       »       »       t.Errorf("Params·mismatch·for·route·'%s'",·request.path)66 »       »       »       t.Errorf("Params·mismatch·for·route·'%s'",·request.path)
58 »       »       }67 »       »       }
59 »       }68 »       }
60 }69 }
  
61 func·checkPriorities(t·*testing.T,·n·*node)·uint32·{70 func·checkPriorities(t·*testing.T,·n·*node)·uint32·{
Offset 78, 41 lines modifiedOffset 89, 19 lines modified
78 »       »       »       n.path,·n.priority,·prio,89 »       »       »       n.path,·n.priority,·prio,
79 »       »       )90 »       »       )
80 »       }91 »       }
  
81 »       return·prio92 »       return·prio
82 }93 }
  
83 func·checkMaxParams(t·*testing.T,·n·*node)·uint8·{ 
84 »       var·maxParams·uint8 
85 »       for·i·:=·range·n.children·{ 
86 »       »       params·:=·checkMaxParams(t,·n.children[i]) 
87 »       »       if·params·>·maxParams·{ 
88 »       »       »       maxParams·=·params 
89 »       »       } 
90 »       } 
91 »       if·n.nType·>·root·&&·!n.wildChild·{ 
92 »       »       maxParams++ 
93 »       } 
  
94 »       if·n.maxParams·!=·maxParams·{ 
95 »       »       t.Errorf( 
96 »       »       »       "maxParams·mismatch·for·node·'%s':·is·%d,·should·be·%d", 
97 »       »       »       n.path,·n.maxParams,·maxParams, 
98 »       »       ) 
99 »       } 
  
100 »       return·maxParams 
101 } 
  
102 func·TestCountParams(t·*testing.T)·{94 func·TestCountParams(t·*testing.T)·{
103 »       if·countParams("/path/:param1/static/*catch-all")·!=·2·{95 »       if·countParams("/path/:param1/static/*catch-all")·!=·2·{
104 »       »       t.Fail()96 »       »       t.Fail()
105 »       }97 »       }
106 »       if·countParams(strings.Repeat("/:param",·256))·!=·255·{98 »       if·countParams(strings.Repeat("/:param",·256))·!=·256·{
107 »       »       t.Fail()99 »       »       t.Fail()
108 »       }100 »       }
109 }101 }
  
110 func·TestTreeAddAndGet(t·*testing.T)·{102 func·TestTreeAddAndGet(t·*testing.T)·{
111 »       tree·:=·&node{}103 »       tree·:=·&node{}
  
Offset 129, 15 lines modifiedOffset 118, 15 lines modified
129 »       »       "/α",118 »       »       "/α",
130 »       »       "/β",119 »       »       "/β",
131 »       }120 »       }
132 »       for·_,·route·:=·range·routes·{121 »       for·_,·route·:=·range·routes·{
133 »       »       tree.addRoute(route,·fakeHandler(route))122 »       »       tree.addRoute(route,·fakeHandler(route))
134 »       }123 »       }
  
135 »       //printChildren(tree,·"")124 »       //·printChildren(tree,·"")
  
136 »       checkRequests(t,·tree,·testRequests{125 »       checkRequests(t,·tree,·testRequests{
137 »       »       {"/a",·false,·"/a",·nil},126 »       »       {"/a",·false,·"/a",·nil},
138 »       »       {"/",·true,·"",·nil},127 »       »       {"/",·true,·"",·nil},
139 »       »       {"/hi",·false,·"/hi",·nil},128 »       »       {"/hi",·false,·"/hi",·nil},
140 »       »       {"/contact",·false,·"/contact",·nil},129 »       »       {"/contact",·false,·"/contact",·nil},
141 »       »       {"/co",·false,·"/co",·nil},130 »       »       {"/co",·false,·"/co",·nil},
Offset 146, 15 lines modifiedOffset 135, 14 lines modified
146 »       »       {"/no",·true,·"",·nil},···//·no·matching·child135 »       »       {"/no",·true,·"",·nil},···//·no·matching·child
Max diff block lines reached; 11036/14531 bytes (75.95%) of diff not shown.