Use pointers to make generic functions work
This commit is contained in:
20
entry.go
20
entry.go
@@ -68,13 +68,13 @@ func NewEntry(title string) *Entry {
|
||||
|
||||
// AddAuthor adds the Person as an author to the Entry.
|
||||
func (e *Entry) AddAuthor(p *Person) {
|
||||
addToSlice(e.Authors, p)
|
||||
addToSlice(&e.Authors, p)
|
||||
e.Updated = NewDate(time.Now())
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if err := deleteFromSlice(&e.Authors, id); err != nil {
|
||||
return fmt.Errorf("error deleting author %v from entry %v: %v", id, e.ID.URI, err)
|
||||
}
|
||||
|
||||
@@ -84,13 +84,13 @@ func (e *Entry) DeleteAuthor(id int) error {
|
||||
|
||||
// AddCategory adds the Category to the Entry.
|
||||
func (e *Entry) AddCategory(c *Category) {
|
||||
addToSlice(e.Categories, c)
|
||||
addToSlice(&e.Categories, c)
|
||||
e.Updated = NewDate(time.Now())
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if err := deleteFromSlice(&e.Categories, id); err != nil {
|
||||
return fmt.Errorf("error deleting category %v from entry %v: %v", id, e.ID.URI, err)
|
||||
}
|
||||
|
||||
@@ -100,13 +100,13 @@ func (e *Entry) DeleteCategory(id int) error {
|
||||
|
||||
// AddContributor adds the Person as a contributor to the Entry.
|
||||
func (e *Entry) AddContributor(c *Person) {
|
||||
addToSlice(e.Contributors, c)
|
||||
addToSlice(&e.Contributors, c)
|
||||
e.Updated = NewDate(time.Now())
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if err := deleteFromSlice(&e.Contributors, id); err != nil {
|
||||
return fmt.Errorf("error deleting contributor %v from entry %v: %v", id, e.ID.URI, err)
|
||||
}
|
||||
|
||||
@@ -116,13 +116,13 @@ func (e *Entry) DeleteContributor(id int) error {
|
||||
|
||||
// AddLink adds the Link to the Entry.
|
||||
func (e *Entry) AddLink(l *Link) {
|
||||
addToSlice(e.Links, l)
|
||||
addToSlice(&e.Links, l)
|
||||
e.Updated = NewDate(time.Now())
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if err := deleteFromSlice(&e.Links, id); err != nil {
|
||||
return fmt.Errorf("error deleting link %v from entry %v: %v", id, e.ID.URI, err)
|
||||
}
|
||||
|
||||
@@ -132,13 +132,13 @@ func (e *Entry) DeleteLink(id int) error {
|
||||
|
||||
// AddExtension adds the ExtensionElement to the Entry.
|
||||
func (e *Entry) AddExtension(x *ExtensionElement) {
|
||||
addToSlice(e.Extensions, x)
|
||||
addToSlice(&e.Extensions, x)
|
||||
e.Updated = NewDate(time.Now())
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if err := deleteFromSlice(&e.Extensions, id); err != nil {
|
||||
return fmt.Errorf("error deleting extension %v from entry %v: %v", id, e.ID.URI, err)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user