@@ -14,15 +14,15 @@ var (
1414 idPattern = `[\d]+`
1515 idKey = `id`
1616 errGenerateParameters = errors .New ("params contains wrong parameters" )
17- errNotFoundRoute = errors .New ("cannot found route in tree" )
18- errNotFoundMethod = errors .New ("cannot found method in tree" )
17+ errNotFoundRoute = errors .New ("cannot find route in tree" )
18+ errNotFoundMethod = errors .New ("cannot find method in tree" )
1919 errPatternGrammar = errors .New ("pattern grammar error" )
20- methods = map [string ]bool {
21- http .MethodGet : true ,
22- http .MethodPost : true ,
23- http .MethodPut : true ,
24- http .MethodDelete : true ,
25- http .MethodPatch : true ,
20+ methods = map [string ]struct {} {
21+ http .MethodGet : {} ,
22+ http .MethodPost : {} ,
23+ http .MethodPut : {} ,
24+ http .MethodDelete : {} ,
25+ http .MethodPatch : {} ,
2626 }
2727)
2828
@@ -118,7 +118,7 @@ func (router *Router) PATCHAndName(path string, handle http.HandlerFunc, routeNa
118118 router .PATCH (path , handle )
119119}
120120
121- // Group define routes groups If there is a path prefix that use `prefix`
121+ // Group define routes groups if there is a path prefix that uses `prefix`
122122func (router * Router ) Group (prefix string ) * Router {
123123 return & Router {
124124 prefix : prefix ,
@@ -190,7 +190,7 @@ func (router *Router) NotFoundFunc(handler http.HandlerFunc) {
190190 router .notFound = handler
191191}
192192
193- // Handle registers a new request handle with the given path and method.
193+ // Handle registers a new request handler with the given path and method.
194194func (router * Router ) Handle (method string , path string , handle http.HandlerFunc ) {
195195 if _ , ok := methods [method ]; ! ok {
196196 panic (fmt .Errorf ("invalid method" ))
@@ -211,21 +211,21 @@ func (router *Router) Handle(method string, path string, handle http.HandlerFunc
211211 tree .Add (path , handle , router .middleware ... )
212212}
213213
214- // GetParam return route param stored in r .
214+ // GetParam returns route param stored in http.request .
215215func GetParam (r * http.Request , key string ) string {
216216 return GetAllParams (r )[key ]
217217}
218218
219219// contextKeyType is a private struct that is used for storing values in net.Context
220220type contextKeyType struct {}
221221
222- // contextKey is the key that is used to store values in the net.Context for each request
222+ // contextKey is the key that is used to store values in net.Context for each request
223223var contextKey = contextKeyType {}
224224
225225// paramsMapType is a private type that is used to store route params
226226type paramsMapType map [string ]string
227227
228- // GetAllParams return all route params stored in r .
228+ // GetAllParams returns all route params stored in http.Request .
229229func GetAllParams (r * http.Request ) paramsMapType {
230230 values , ok := r .Context ().Value (contextKey ).(paramsMapType )
231231 if ok {
@@ -309,7 +309,7 @@ func (router *Router) HandleNotFound(w http.ResponseWriter, r *http.Request, mid
309309 http .NotFound (w , r )
310310}
311311
312- // handle execute middleware chain
312+ // handle executes middleware chain
313313func handle (w http.ResponseWriter , r * http.Request , handler http.HandlerFunc , middleware []MiddlewareType ) {
314314 var baseHandler = handler
315315 for _ , m := range middleware {
@@ -318,13 +318,13 @@ func handle(w http.ResponseWriter, r *http.Request, handler http.HandlerFunc, mi
318318 baseHandler (w , r )
319319}
320320
321- // Match check if the request match the route Pattern
321+ // Match checks if the request matches the route pattern
322322func (router * Router ) Match (requestUrl string , path string ) bool {
323323 _ , ok := router .matchAndParse (requestUrl , path )
324324 return ok
325325}
326326
327- // matchAndParse check if the request matches the route path and returns a map of the parsed
327+ // matchAndParse checks if the request matches the route path and returns a map of the parsed
328328func (router * Router ) matchAndParse (requestUrl string , path string ) (paramsMapType , bool ) {
329329 res := strings .Split (path , "/" )
330330
0 commit comments