Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 471: Fix panic when removing a route that doesn't exist in w.routes. #472

Merged
merged 2 commits into from
Jul 14, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 14 additions & 16 deletions web_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,20 @@ func (w *WebService) Route(builder *RouteBuilder) *WebService {

// RemoveRoute removes the specified route, looks for something that matches 'path' and 'method'
func (w *WebService) RemoveRoute(path, method string) error {
if !w.dynamicRoutes {
return errors.New("dynamic routes are not enabled.")
}
w.routesLock.Lock()
defer w.routesLock.Unlock()
newRoutes := make([]Route, (len(w.routes) - 1))
current := 0
for ix := range w.routes {
if w.routes[ix].Method == method && w.routes[ix].Path == path {
continue
}
newRoutes[current] = w.routes[ix]
current++
}
w.routes = newRoutes
return nil
if !w.dynamicRoutes {
return errors.New("dynamic routes are not enabled.")
}
w.routesLock.Lock()
defer w.routesLock.Unlock()
newRoutes := make([]Route, 0)
jeffreydwalter marked this conversation as resolved.
Show resolved Hide resolved
for ix := range w.routes {
jeffreydwalter marked this conversation as resolved.
Show resolved Hide resolved
if w.routes[ix].Method == method && w.routes[ix].Path == path {
continue
}
newRoutes = append(newRoutes, w.routes[ix])
}
w.routes = newRoutes
return nil
}

// Method creates a new RouteBuilder and initialize its http method
Expand Down