From 92f284a1a620349d1ff3e3583722f919163b82a0 Mon Sep 17 00:00:00 2001 From: Nagy Salem Date: Tue, 26 May 2020 12:30:49 +0300 Subject: [PATCH] Fix deepsource issues (#24) * fixed shadow of builtin len and anti pattern * Refactored not needed select with single case to a simple channel receive --- gearbox_test.go | 9 +++------ router.go | 12 ++++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/gearbox_test.go b/gearbox_test.go index f79483e..654537c 100644 --- a/gearbox_test.go +++ b/gearbox_test.go @@ -66,11 +66,8 @@ func makeRequest(request *http.Request, gb *gearbox) (*http.Response, error) { ch <- gb.httpServer.ServeConn(c) }() - select { - case err = <-ch: - if err != nil { - return nil, err - } + if err = <-ch; err != nil { + return nil, err } // Parse response @@ -108,7 +105,7 @@ var emptyMiddleware = func(ctx *Context) { } // registerRoute matches with register route request with available methods and calls it -func registerRoute(gb Gearbox, method string, path string, handler func(ctx *Context)) { +func registerRoute(gb Gearbox, method, path string, handler func(ctx *Context)) { switch method { case MethodGet: gb.Get(path, handler) diff --git a/router.go b/router.go index c4756cf..fbfbe4e 100644 --- a/router.go +++ b/router.go @@ -46,7 +46,7 @@ func validateRoutePath(path []byte) error { } // registerRoute registers handler with method and path -func (gb *gearbox) registerRoute(method []byte, path []byte, handlers handlersChain) error { +func (gb *gearbox) registerRoute(method, path []byte, handlers handlersChain) error { // Handler is not provided if handlers == nil { return fmt.Errorf("route %s with method %s does not contain any handlers", path, method) @@ -135,7 +135,7 @@ func (gb *gearbox) constructRoutingTree() error { } // matchRoute matches provided method and path with handler if it's existing -func (gb *gearbox) matchRoute(method []byte, path []byte) handlersChain { +func (gb *gearbox) matchRoute(method, path []byte) handlersChain { if handlers := gb.matchRouteAgainstRegistered(method, path); handlers != nil { return handlers } @@ -148,16 +148,16 @@ func (gb *gearbox) matchRoute(method []byte, path []byte) handlersChain { } // getKeywordEnd gets index of last byte before next '/' starting from index start -func getKeywordEnd(start int, path *[]byte, len int) int { - for i := start; i < len; i++ { +func getKeywordEnd(start int, path *[]byte, length int) int { + for i := start; i < length; i++ { if (*path)[i] == '/' { return i } } - return len + return length } -func (gb *gearbox) matchRouteAgainstRegistered(method []byte, path []byte) handlersChain { +func (gb *gearbox) matchRouteAgainstRegistered(method, path []byte) handlersChain { // Start with root node currentNode := gb.routingTreeRoot