Skip to content

Commit

Permalink
fix: refactor delete from slice
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Selivanov committed Jul 14, 2023
1 parent 61cbbd5 commit 381a8e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion services_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (l *ServicesList) RemoveFromHealthyByIndex(i int) {
logger.Log().Warn(fmt.Errorf("unexpected error during service Close(): %w", err).Error())
}

l.healthy = append(l.healthy[:i], l.healthy[i+1:]...)
l.healthy = deleteFromSlice(l.healthy, i)
}

// RemoveFromJail remove given
Expand Down
7 changes: 4 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func Sleep(t time.Duration, cancelCh <-chan struct{}) {
// deleteFromSlice delete item with
// given index from provided slice
func deleteFromSlice(slice []service.IService, index int) []service.IService {
copy(slice[index:], slice[index+1:])
slice[len(slice)-1] = nil
return slice[:len(slice)-1]
//https://stackoverflow.com/questions/37334119/how-to-delete-an-element-from-a-slice-in-golang
temp := make([]service.IService, 0)
temp = append(temp, slice[:index]...)
return append(temp, slice[index+1:]...)
}

0 comments on commit 381a8e6

Please sign in to comment.