@@ -23,6 +23,16 @@ type (
2323)
2424
2525const (
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.
3660func 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.
101125func (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.
106130func (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.
111135func (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.
116140func (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.
121145func (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.
126150func (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.
131155func (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.
136160func (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.
141165func (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
165189func (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}
0 commit comments