Skip to content

Instantly share code, notes, and snippets.

@Integralist
Created December 3, 2024 07:10
Show Gist options
  • Save Integralist/d21ee193a83fdf68bc3fa506f25782fe to your computer and use it in GitHub Desktop.
Save Integralist/d21ee193a83fdf68bc3fa506f25782fe to your computer and use it in GitHub Desktop.
[Delete a slice entry in Go] #go #golang #slices
// zones == complete list of dns zones
// denyList == list of zones to remove
for _, deniedZone := range denyList {
for i := 0; i < len(zones); i++ {
if zones[i] == deniedZone {
zones = append(zones[:i], zones[i+1:]...)
i-- // Adjust index to stay at the correct position after removal
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment