Skip to content

Commit 181d948

Browse files
committed
Fixed #9
Signed-off-by: Vishal Rana <[email protected]>
1 parent cd9fc7f commit 181d948

File tree

5 files changed

+161
-190
lines changed

5 files changed

+161
-190
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,32 +111,32 @@ func main() {
111111
```
112112

113113
### Benchmark
114-
Based on [julienschmidt/go-http-routing-benchmark] (https://github.com/vishr/go-http-routing-benchmark), March 25, 2015
114+
Based on [julienschmidt/go-http-routing-benchmark] (https://github.com/vishr/go-http-routing-benchmark), April 1, 2015
115115
##### [GitHub API](http://developer.github.com/v3)
116116
```
117-
BenchmarkAce_GithubAll 20000 70318 ns/op 13792 B/op 167 allocs/op
118-
BenchmarkBear_GithubAll 10000 262758 ns/op 79952 B/op 943 allocs/op
119-
BenchmarkBeego_GithubAll 3000 504264 ns/op 146272 B/op 2092 allocs/op
120-
BenchmarkEcho_GithubAll 30000 45349 ns/op 0 B/op 0 allocs/op
121-
BenchmarkBone_GithubAll 1000 2058931 ns/op 648016 B/op 8119 allocs/op
122-
BenchmarkDenco_GithubAll 20000 79656 ns/op 20224 B/op 167 allocs/op
123-
BenchmarkGin_GithubAll 20000 71009 ns/op 13792 B/op 167 allocs/op
124-
BenchmarkGocraftWeb_GithubAll 5000 384342 ns/op 133280 B/op 1889 allocs/op
125-
BenchmarkGoji_GithubAll 3000 565323 ns/op 56113 B/op 334 allocs/op
126-
BenchmarkGoJsonRest_GithubAll 5000 461591 ns/op 135995 B/op 2940 allocs/op
127-
BenchmarkGoRestful_GithubAll 200 8828847 ns/op 649139 B/op 7355 allocs/op
128-
BenchmarkGorillaMux_GithubAll 200 6794821 ns/op 153137 B/op 1791 allocs/op
129-
BenchmarkHttpRouter_GithubAll 30000 51688 ns/op 13792 B/op 167 allocs/op
130-
BenchmarkHttpTreeMux_GithubAll 10000 136677 ns/op 56112 B/op 334 allocs/op
131-
BenchmarkKocha_GithubAll 10000 145115 ns/op 23304 B/op 843 allocs/op
132-
BenchmarkMacaron_GithubAll 2000 684714 ns/op 224960 B/op 2315 allocs/op
133-
BenchmarkMartini_GithubAll 100 10501805 ns/op 237953 B/op 2686 allocs/op
134-
BenchmarkPat_GithubAll 500 3987941 ns/op 1504101 B/op 32222 allocs/op
135-
BenchmarkRevel_GithubAll 2000 1127175 ns/op 345553 B/op 5918 allocs/op
136-
BenchmarkRivet_GithubAll 10000 239793 ns/op 84272 B/op 1079 allocs/op
137-
BenchmarkTango_GithubAll 500 3452359 ns/op 1338664 B/op 27736 allocs/op
138-
BenchmarkTigerTonic_GithubAll 2000 951609 ns/op 241088 B/op 6052 allocs/op
139-
BenchmarkTraffic_GithubAll 200 7496057 ns/op 2664761 B/op 22390 allocs/op
140-
BenchmarkVulcan_GithubAll 5000 300807 ns/op 19894 B/op 609 allocs/op
141-
BenchmarkZeus_GithubAll 2000 801269 ns/op 300688 B/op 2648 allocs/op
117+
BenchmarkAce_GithubAll 20000 69126 ns/op 13792 B/op 167 allocs/op
118+
BenchmarkBear_GithubAll 10000 252699 ns/op 79952 B/op 943 allocs/op
119+
BenchmarkBeego_GithubAll 3000 485692 ns/op 146272 B/op 2092 allocs/op
120+
BenchmarkEcho_GithubAll 30000 43700 ns/op 0 B/op 0 allocs/op
121+
BenchmarkBone_GithubAll 1000 2158467 ns/op 648016 B/op 8119 allocs/op
122+
BenchmarkDenco_GithubAll 20000 83022 ns/op 20224 B/op 167 allocs/op
123+
BenchmarkGin_GithubAll 20000 72317 ns/op 13792 B/op 167 allocs/op
124+
BenchmarkGocraftWeb_GithubAll 5000 381554 ns/op 133280 B/op 1889 allocs/op
125+
BenchmarkGoji_GithubAll 3000 605232 ns/op 56113 B/op 334 allocs/op
126+
BenchmarkGoJsonRest_GithubAll 5000 467810 ns/op 135995 B/op 2940 allocs/op
127+
BenchmarkGoRestful_GithubAll 200 9345441 ns/op 707604 B/op 7558 allocs/op
128+
BenchmarkGorillaMux_GithubAll 200 7043040 ns/op 153136 B/op 1791 allocs/op
129+
BenchmarkHttpRouter_GithubAll 30000 52251 ns/op 13792 B/op 167 allocs/op
130+
BenchmarkHttpTreeMux_GithubAll 10000 145114 ns/op 56112 B/op 334 allocs/op
131+
BenchmarkKocha_GithubAll 10000 145061 ns/op 23304 B/op 843 allocs/op
132+
BenchmarkMacaron_GithubAll 2000 697957 ns/op 224960 B/op 2315 allocs/op
133+
BenchmarkMartini_GithubAll 100 11651997 ns/op 237953 B/op 2686 allocs/op
134+
BenchmarkPat_GithubAll 300 3951799 ns/op 1504101 B/op 32222 allocs/op
135+
BenchmarkRevel_GithubAll 2000 1129370 ns/op 345553 B/op 5918 allocs/op
136+
BenchmarkRivet_GithubAll 10000 246564 ns/op 84272 B/op 1079 allocs/op
137+
BenchmarkTango_GithubAll 500 3544850 ns/op 1338664 B/op 27736 allocs/op
138+
BenchmarkTigerTonic_GithubAll 2000 979370 ns/op 241088 B/op 6052 allocs/op
139+
BenchmarkTraffic_GithubAll 200 7508743 ns/op 2664762 B/op 22390 allocs/op
140+
BenchmarkVulcan_GithubAll 5000 286727 ns/op 19894 B/op 609 allocs/op
141+
BenchmarkZeus_GithubAll 2000 798335 ns/op 300688 B/op 2648 allocs/op
142142
```

echo.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ type (
2323
)
2424

2525
const (
26+
MethodCONNECT = "CONNECT"
27+
MethodDELETE = "DELETE"
28+
MethodGET = "GET"
29+
MethodHEAD = "HEAD"
30+
MethodOPTIONS = "OPTIONS"
31+
MethodPATCH = "PATCH"
32+
MethodPOST = "POST"
33+
MethodPUT = "PUT"
34+
MethodTRACE = "TRACE"
35+
2636
MIMEJSON = "application/json"
2737
MIMEText = "text/plain"
2838

@@ -32,6 +42,20 @@ const (
3242
HeaderContentType = "Content-Type"
3343
)
3444

45+
var (
46+
methods = []string{
47+
MethodCONNECT,
48+
MethodDELETE,
49+
MethodGET,
50+
MethodHEAD,
51+
MethodOPTIONS,
52+
MethodPATCH,
53+
MethodPOST,
54+
MethodPUT,
55+
MethodTRACE,
56+
}
57+
)
58+
3559
// New creates a echo instance.
3660
func New() (e *Echo) {
3761
e = &Echo{
@@ -99,47 +123,47 @@ func (e *Echo) Use(m ...Middleware) {
99123

100124
// Connect adds a CONNECT route > handler to the router.
101125
func (e *Echo) Connect(path string, h Handler) {
102-
e.Router.Add("CONNECT", path, wrapH(h))
126+
e.Router.Add(MethodCONNECT, path, wrapH(h))
103127
}
104128

105129
// Delete adds a DELETE route > handler to the router.
106130
func (e *Echo) Delete(path string, h Handler) {
107-
e.Router.Add("DELETE", path, wrapH(h))
131+
e.Router.Add(MethodDELETE, path, wrapH(h))
108132
}
109133

110134
// Get adds a GET route > handler to the router.
111135
func (e *Echo) Get(path string, h Handler) {
112-
e.Router.Add("GET", path, wrapH(h))
136+
e.Router.Add(MethodGET, path, wrapH(h))
113137
}
114138

115139
// Head adds a HEAD route > handler to the router.
116140
func (e *Echo) Head(path string, h Handler) {
117-
e.Router.Add("HEAD", path, wrapH(h))
141+
e.Router.Add(MethodHEAD, path, wrapH(h))
118142
}
119143

120144
// Options adds an OPTIONS route > handler to the router.
121145
func (e *Echo) Options(path string, h Handler) {
122-
e.Router.Add("OPTIONS", path, wrapH(h))
146+
e.Router.Add(MethodOPTIONS, path, wrapH(h))
123147
}
124148

125149
// Patch adds a PATCH route > handler to the router.
126150
func (e *Echo) Patch(path string, h Handler) {
127-
e.Router.Add("PATCH", path, wrapH(h))
151+
e.Router.Add(MethodPATCH, path, wrapH(h))
128152
}
129153

130154
// Post adds a POST route > handler to the router.
131155
func (e *Echo) Post(path string, h Handler) {
132-
e.Router.Add("POST", path, wrapH(h))
156+
e.Router.Add(MethodPOST, path, wrapH(h))
133157
}
134158

135159
// Put adds a PUT route > handler to the router.
136160
func (e *Echo) Put(path string, h Handler) {
137-
e.Router.Add("PUT", path, wrapH(h))
161+
e.Router.Add(MethodPUT, path, wrapH(h))
138162
}
139163

140164
// Trace adds a TRACE route > handler to the router.
141165
func (e *Echo) Trace(path string, h Handler) {
142-
e.Router.Add("TRACE", path, wrapH(h))
166+
e.Router.Add(MethodTRACE, path, wrapH(h))
143167
}
144168

145169
// Static serves static files.
@@ -163,7 +187,7 @@ func (e *Echo) Index(file string) {
163187
}
164188

165189
func (e *Echo) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
166-
h, c, s := e.Router.Find(r.Method, r.URL.Path)
190+
h, c := e.Router.Find(r.Method, r.URL.Path)
167191
c.reset(rw, r)
168192
if h != nil {
169193
// Middleware
@@ -173,11 +197,7 @@ func (e *Echo) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
173197
// Handler
174198
h(c)
175199
} else {
176-
if s == NotFound {
177-
e.notFoundHandler(c)
178-
} else if s == NotAllowed {
179-
e.methodNotAllowedHandler(c)
180-
}
200+
e.notFoundHandler(c)
181201
}
182202
e.pool.Put(c)
183203
}

echo_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func TestEchoMethod(t *testing.T) {
153153
// if h == nil {
154154
// t.Error("should find route for GET")
155155
// }
156-
157156
}
158157

159158
func TestEchoServeHTTP(t *testing.T) {
@@ -178,12 +177,12 @@ func TestEchoServeHTTP(t *testing.T) {
178177
}
179178

180179
// NotAllowed
181-
r, _ = http.NewRequest("POST", "/users", nil)
182-
w = httptest.NewRecorder()
183-
e.ServeHTTP(w, r)
184-
if w.Code != http.StatusMethodNotAllowed {
185-
t.Errorf("status code should be 405, found %d", w.Code)
186-
}
180+
// r, _ = http.NewRequest("POST", "/users", nil)
181+
// w = httptest.NewRecorder()
182+
// e.ServeHTTP(w, r)
183+
// if w.Code != http.StatusMethodNotAllowed {
184+
// t.Errorf("status code should be 405, found %d", w.Code)
185+
// }
187186
}
188187

189188
func verifyUser(rd io.Reader, t *testing.T) {

0 commit comments

Comments
 (0)