Skip to content

Commit

Permalink
Merge pull request #4 from SvenDowideit/master
Browse files Browse the repository at this point in the history
use a more naive approach to removing an element from a list
  • Loading branch information
obynio authored Jan 25, 2024
2 parents 829a16e + 334bbf2 commit da32615
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ func (p *Provider) deleteRecord(ctx context.Context, zone string, record libdns.

if len(rec.RRSetValues) > 1 {
// if it contains multiple values, the best is to update the record instead of deleting all the values
for i, val := range rec.RRSetValues {
if val == record.Value {
rec.RRSetValues[len(rec.RRSetValues)-1], rec.RRSetValues[i] = rec.RRSetValues[i], rec.RRSetValues[len(rec.RRSetValues)-1]
rec.RRSetValues = rec.RRSetValues[:len(rec.RRSetValues)-1]
newRRSetValues := []string{}
for _, val := range rec.RRSetValues {
if val != record.Value {
newRRSetValues = append(newRRSetValues, val)
}
}
rec.RRSetValues = newRRSetValues

raw, err := json.Marshal(rec)
if err != nil {
Expand Down

0 comments on commit da32615

Please sign in to comment.