From bcf25323722a76f8d00055ef3403812ffe93bba0 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sun, 20 Oct 2024 12:35:26 +0200 Subject: [PATCH] Rename id in Delete methods to index --- atom.go | 8 ++++---- commonAttributes.go | 6 +++--- entry.go | 30 +++++++++++++++--------------- feed.go | 36 ++++++++++++++++++------------------ person.go | 6 +++--- source.go | 30 +++++++++++++++--------------- 6 files changed, 58 insertions(+), 58 deletions(-) diff --git a/atom.go b/atom.go index bb7dd31..34f5550 100644 --- a/atom.go +++ b/atom.go @@ -26,13 +26,13 @@ func addToSlice[C Countable](slice *[]C, countable C) { // deleteFromSlice deletes the Countable with the index from the *[]Countable. // It return an error. -func deleteFromSlice[C Countable](slice *[]C, id int) error { +func deleteFromSlice[C Countable](slice *[]C, index int) error { length := len(*slice) - if id > length { - return fmt.Errorf("id %v out of range %v", id, length) + if index > length { + return fmt.Errorf("id %v out of range %v", index, length) } - *slice = append((*slice)[:id], (*slice)[id+1:]...) + *slice = append((*slice)[:index], (*slice)[index+1:]...) return nil } diff --git a/commonAttributes.go b/commonAttributes.go index 6cd6a28..8035734 100644 --- a/commonAttributes.go +++ b/commonAttributes.go @@ -24,9 +24,9 @@ func (c *CommonAttributes) AddAttribute(name, value string) { // DeleteAttribute deletes the attribute from the CommonAttributes. It return an // error. -func (c *CommonAttributes) DeleteAttribute(id int) error { - if err := deleteFromSlice(&c.UndefinedAttributes, id); err != nil { - return fmt.Errorf("error deleting undefined attribute %v from common attributes %v: %v", id, c, err) +func (c *CommonAttributes) DeleteAttribute(index int) error { + if err := deleteFromSlice(&c.UndefinedAttributes, index); err != nil { + return fmt.Errorf("error deleting undefined attribute %v from common attributes %v: %v", index, c, err) } return nil } diff --git a/entry.go b/entry.go index 2eddb28..67ccd7b 100644 --- a/entry.go +++ b/entry.go @@ -73,9 +73,9 @@ func (e *Entry) AddAuthor(p *Person) { } // DeleteAuthor deletes the Person from the Entry. It return an error. -func (e *Entry) DeleteAuthor(id int) error { - if err := deleteFromSlice(&e.Authors, id); err != nil { - return fmt.Errorf("error deleting author %v from entry %v: %v", id, e.ID.URI, err) +func (e *Entry) DeleteAuthor(index int) error { + if err := deleteFromSlice(&e.Authors, index); err != nil { + return fmt.Errorf("error deleting author %v from entry %v: %v", index, e.ID.URI, err) } e.Updated = NewDate(time.Now()) @@ -89,9 +89,9 @@ func (e *Entry) AddCategory(c *Category) { } // DeleteCategory deletes the Category from the Entry. It return an error. -func (e *Entry) DeleteCategory(id int) error { - if err := deleteFromSlice(&e.Categories, id); err != nil { - return fmt.Errorf("error deleting category %v from entry %v: %v", id, e.ID.URI, err) +func (e *Entry) DeleteCategory(index int) error { + if err := deleteFromSlice(&e.Categories, index); err != nil { + return fmt.Errorf("error deleting category %v from entry %v: %v", index, e.ID.URI, err) } e.Updated = NewDate(time.Now()) @@ -105,9 +105,9 @@ func (e *Entry) AddContributor(c *Person) { } // DeleteContributor deletes the Person from the Entry. It return an error. -func (e *Entry) DeleteContributor(id int) error { - if err := deleteFromSlice(&e.Contributors, id); err != nil { - return fmt.Errorf("error deleting contributor %v from entry %v: %v", id, e.ID.URI, err) +func (e *Entry) DeleteContributor(index int) error { + if err := deleteFromSlice(&e.Contributors, index); err != nil { + return fmt.Errorf("error deleting contributor %v from entry %v: %v", index, e.ID.URI, err) } e.Updated = NewDate(time.Now()) @@ -121,9 +121,9 @@ func (e *Entry) AddLink(l *Link) { } // DeleteLink deletes the Link from the Entry. It return an error. -func (e *Entry) DeleteLink(id int) error { - if err := deleteFromSlice(&e.Links, id); err != nil { - return fmt.Errorf("error deleting link %v from entry %v: %v", id, e.ID.URI, err) +func (e *Entry) DeleteLink(index int) error { + if err := deleteFromSlice(&e.Links, index); err != nil { + return fmt.Errorf("error deleting link %v from entry %v: %v", index, e.ID.URI, err) } e.Updated = NewDate(time.Now()) @@ -137,9 +137,9 @@ func (e *Entry) AddExtension(x *ExtensionElement) { } // DeleteExtension deletes the Extension from the Entry. It return an error. -func (e *Entry) DeleteExtension(id int) error { - if err := deleteFromSlice(&e.Extensions, id); err != nil { - return fmt.Errorf("error deleting extension %v from entry %v: %v", id, e.ID.URI, err) +func (e *Entry) DeleteExtension(index int) error { + if err := deleteFromSlice(&e.Extensions, index); err != nil { + return fmt.Errorf("error deleting extension %v from entry %v: %v", index, e.ID.URI, err) } e.Updated = NewDate(time.Now()) diff --git a/feed.go b/feed.go index e4ea920..08851d2 100644 --- a/feed.go +++ b/feed.go @@ -42,9 +42,9 @@ func (f *Feed) AddAuthor(p *Person) { } // DeleteAuthor deletes the Person from the Feed. It return an error. -func (f *Feed) DeleteAuthor(id int) error { - if err := deleteFromSlice(&f.Authors, id); err != nil { - return fmt.Errorf("error deleting author %v from entry %v: %v", id, f.ID.URI, err) +func (f *Feed) DeleteAuthor(index int) error { + if err := deleteFromSlice(&f.Authors, index); err != nil { + return fmt.Errorf("error deleting author %v from entry %v: %v", index, f.ID.URI, err) } f.Updated = NewDate(time.Now()) @@ -58,9 +58,9 @@ func (f *Feed) AddCategory(c *Category) { } // DeleteCategory deletes the Category from the Feed. It return an error. -func (f *Feed) DeleteCategory(id int) error { - if err := deleteFromSlice(&f.Categories, id); err != nil { - return fmt.Errorf("error deleting category %v from entry %v: %v", id, f.ID.URI, err) +func (f *Feed) DeleteCategory(index int) error { + if err := deleteFromSlice(&f.Categories, index); err != nil { + return fmt.Errorf("error deleting category %v from entry %v: %v", index, f.ID.URI, err) } f.Updated = NewDate(time.Now()) @@ -74,9 +74,9 @@ func (f *Feed) AddContributor(c *Person) { } // DeleteContributor deletes the Person from the Feed. It return an error. -func (f *Feed) DeleteContributor(id int) error { - if err := deleteFromSlice(&f.Contributors, id); err != nil { - return fmt.Errorf("error deleting contributor %v from entry %v: %v", id, f.ID.URI, err) +func (f *Feed) DeleteContributor(index int) error { + if err := deleteFromSlice(&f.Contributors, index); err != nil { + return fmt.Errorf("error deleting contributor %v from entry %v: %v", index, f.ID.URI, err) } f.Updated = NewDate(time.Now()) @@ -90,9 +90,9 @@ func (f *Feed) AddLink(l *Link) { } // DeleteLink deletes the Link from the Feed. It return an error. -func (f *Feed) DeleteLink(id int) error { - if err := deleteFromSlice(&f.Links, id); err != nil { - return fmt.Errorf("error deleting link %v from entry %v: %v", id, f.ID.URI, err) +func (f *Feed) DeleteLink(index int) error { + if err := deleteFromSlice(&f.Links, index); err != nil { + return fmt.Errorf("error deleting link %v from entry %v: %v", index, f.ID.URI, err) } f.Updated = NewDate(time.Now()) @@ -106,9 +106,9 @@ func (f *Feed) AddExtension(e *ExtensionElement) { } // DeleteExtension deletes the Extension from the Feed. It return an error. -func (f *Feed) DeleteExtension(id int) error { - if err := deleteFromSlice(&f.Extensions, id); err != nil { - return fmt.Errorf("error deleting extension %v from entry %v: %v", id, f.ID.URI, err) +func (f *Feed) DeleteExtension(index int) error { + if err := deleteFromSlice(&f.Extensions, index); err != nil { + return fmt.Errorf("error deleting extension %v from entry %v: %v", index, f.ID.URI, err) } f.Updated = NewDate(time.Now()) @@ -122,9 +122,9 @@ func (f *Feed) AddEntry(e *Entry) { } // DeleteEntry deletes the Entry from the Feed. It return an error. -func (f *Feed) DeleteEntry(id int) error { - if err := deleteFromSlice(&f.Entries, id); err != nil { - return fmt.Errorf("error deleting entry %v from entry %v: %v", id, f.ID.URI, err) +func (f *Feed) DeleteEntry(index int) error { + if err := deleteFromSlice(&f.Entries, index); err != nil { + return fmt.Errorf("error deleting entry %v from entry %v: %v", index, f.ID.URI, err) } f.Updated = NewDate(time.Now()) diff --git a/person.go b/person.go index 1cd928b..d2a0d68 100644 --- a/person.go +++ b/person.go @@ -27,9 +27,9 @@ func (p *Person) AddExtension(e *ExtensionElement) { } // DeleteExtension deletes the Extension from the Person. It return an error. -func (p *Person) DeleteExtension(id int) error { - if err := deleteFromSlice(&p.Extensions, id); err != nil { - return fmt.Errorf("error deleting extension %v from person %v: %v", id, p, err) +func (p *Person) DeleteExtension(index int) error { + if err := deleteFromSlice(&p.Extensions, index); err != nil { + return fmt.Errorf("error deleting extension %v from person %v: %v", index, p, err) } return nil } diff --git a/source.go b/source.go index ee12850..cb2419b 100644 --- a/source.go +++ b/source.go @@ -34,9 +34,9 @@ func (s *Source) AddAuthor(p *Person) { } // DeleteAuthor deletes the Person from the Source. It return an error. -func (s *Source) DeleteAuthor(id int) error { - if err := deleteFromSlice(&s.Authors, id); err != nil { - return fmt.Errorf("error deleting author %v from source %v: %v", id, s, err) +func (s *Source) DeleteAuthor(index int) error { + if err := deleteFromSlice(&s.Authors, index); err != nil { + return fmt.Errorf("error deleting author %v from source %v: %v", index, s, err) } return nil } @@ -47,9 +47,9 @@ func (s *Source) AddCategory(c *Category) { } // DeleteCategory deletes the Category from the Source. It return an error. -func (s *Source) DeleteCategory(id int) error { - if err := deleteFromSlice(&s.Categories, id); err != nil { - return fmt.Errorf("error deleting category %v from source %v: %v", id, s, err) +func (s *Source) DeleteCategory(index int) error { + if err := deleteFromSlice(&s.Categories, index); err != nil { + return fmt.Errorf("error deleting category %v from source %v: %v", index, s, err) } return nil } @@ -60,9 +60,9 @@ func (s *Source) AddContributor(c *Person) { } // DeleteContributor deletes the Person from the Source. It return an error. -func (s *Source) DeleteContributor(id int) error { - if err := deleteFromSlice(&s.Contributors, id); err != nil { - return fmt.Errorf("error deleting contributor %v from source %v: %v", id, s, err) +func (s *Source) DeleteContributor(index int) error { + if err := deleteFromSlice(&s.Contributors, index); err != nil { + return fmt.Errorf("error deleting contributor %v from source %v: %v", index, s, err) } return nil } @@ -73,9 +73,9 @@ func (s *Source) AddLink(l *Link) { } // DeleteLink deletes the Link from the Source. It return an error. -func (s *Source) DeleteLink(id int) error { - if err := deleteFromSlice(&s.Links, id); err != nil { - return fmt.Errorf("error deleting link %v from source %v: %v", id, s, err) +func (s *Source) DeleteLink(index int) error { + if err := deleteFromSlice(&s.Links, index); err != nil { + return fmt.Errorf("error deleting link %v from source %v: %v", index, s, err) } return nil } @@ -86,9 +86,9 @@ func (s *Source) AddExtension(e *ExtensionElement) { } // DeleteExtension deletes the Extension from the Source. It return an error. -func (s *Source) DeleteExtension(id int) error { - if err := deleteFromSlice(&s.Extensions, id); err != nil { - return fmt.Errorf("error deleting extension %v from source %v: %v", id, s, err) +func (s *Source) DeleteExtension(index int) error { + if err := deleteFromSlice(&s.Extensions, index); err != nil { + return fmt.Errorf("error deleting extension %v from source %v: %v", index, s, err) } return nil }