Skip to content

Commit

Permalink
Fix deepsource issues (#24)
Browse files Browse the repository at this point in the history
* fixed shadow of builtin len and anti pattern

* Refactored not needed select with single case to a simple channel receive
  • Loading branch information
muhammednagy authored May 26, 2020
1 parent 7d42b38 commit 92f284a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
9 changes: 3 additions & 6 deletions gearbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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

Expand Down

0 comments on commit 92f284a

Please sign in to comment.