Skip to content

Instantly share code, notes, and snippets.

@JakeTheCorn
Created July 14, 2018 04:44
Show Gist options
  • Save JakeTheCorn/cae1983b6efe93904af097fe1801a02e to your computer and use it in GitHub Desktop.
Save JakeTheCorn/cae1983b6efe93904af097fe1801a02e to your computer and use it in GitHub Desktop.
Remove Item from Slice in Go
func (cg *ColorGroup) removeColor(colorToRemove string) (int, error) {
colorRemoved := false
for i, c := range cg.Colors {
if colorToRemove == c {
cg.Colors = append(cg.Colors[:i], cg.Colors[i+1:]...)
colorRemoved = true
}
}
if colorRemoved {
return 0, nil
}
return -1, errors.New("Could Not Find Color to Remove")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment