Use pointers to make generic functions work

This commit is contained in:
2024-10-20 12:20:25 +02:00
parent 8a00759c4b
commit c0f5306715
6 changed files with 43 additions and 45 deletions

View File

@@ -30,12 +30,12 @@ func NewSource() *Source {
// AddAuthor adds the Person as an author to the Source.
func (s *Source) AddAuthor(p *Person) {
addToSlice(s.Authors, p)
addToSlice(&s.Authors, p)
}
// 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 {
if err := deleteFromSlice(&s.Authors, id); err != nil {
return fmt.Errorf("error deleting author %v from source %v: %v", id, s, err)
}
return nil
@@ -43,12 +43,12 @@ func (s *Source) DeleteAuthor(id int) error {
// AddCategory adds the Category to the Source.
func (s *Source) AddCategory(c *Category) {
addToSlice(s.Categories, c)
addToSlice(&s.Categories, c)
}
// 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 {
if err := deleteFromSlice(&s.Categories, id); err != nil {
return fmt.Errorf("error deleting category %v from source %v: %v", id, s, err)
}
return nil
@@ -56,12 +56,12 @@ func (s *Source) DeleteCategory(id int) error {
// AddContributor adds the Person as a contributor to the Source.
func (s *Source) AddContributor(c *Person) {
addToSlice(s.Contributors, c)
addToSlice(&s.Contributors, c)
}
// 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 {
if err := deleteFromSlice(&s.Contributors, id); err != nil {
return fmt.Errorf("error deleting contributor %v from source %v: %v", id, s, err)
}
return nil
@@ -69,12 +69,12 @@ func (s *Source) DeleteContributor(id int) error {
// AddLink adds the Link to the Source.
func (s *Source) AddLink(l *Link) {
addToSlice(s.Links, l)
addToSlice(&s.Links, l)
}
// 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 {
if err := deleteFromSlice(&s.Links, id); err != nil {
return fmt.Errorf("error deleting link %v from source %v: %v", id, s, err)
}
return nil
@@ -82,12 +82,12 @@ func (s *Source) DeleteLink(id int) error {
// AddExtension adds the ExtensionElement to the Source.
func (s *Source) AddExtension(e *ExtensionElement) {
addToSlice(s.Extensions, e)
addToSlice(&s.Extensions, e)
}
// 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 {
if err := deleteFromSlice(&s.Extensions, id); err != nil {
return fmt.Errorf("error deleting extension %v from source %v: %v", id, s, err)
}
return nil