Added Delete methods for slice elements to common attributes, entry, feed, person and source
This commit is contained in:
65
source.go
65
source.go
@@ -28,7 +28,7 @@ func NewSource() *Source {
|
||||
return &Source{CommonAttributes: newCommonAttributes()}
|
||||
}
|
||||
|
||||
// AddAuthor adds the Person as an author to the Entry.
|
||||
// AddAuthor adds the Person as an author to the Source.
|
||||
func (s *Source) AddAuthor(p *Person) {
|
||||
if s.Authors == nil {
|
||||
s.Authors = make([]*Person, 1)
|
||||
@@ -38,7 +38,18 @@ func (s *Source) AddAuthor(p *Person) {
|
||||
}
|
||||
}
|
||||
|
||||
// AddCategory adds the Category to the Entry.
|
||||
// DeleteAuthor deletes the Person from the Source. It return an error.
|
||||
func (s *Source) DeleteAuthor(id int) error {
|
||||
length := len(s.Authors)
|
||||
if id > length {
|
||||
return fmt.Errorf("error deleting author from source %v: id %v out of range %v", s, id, length)
|
||||
}
|
||||
|
||||
s.Authors = append(s.Authors[:id], s.Authors[id+1:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddCategory adds the Category to the Source.
|
||||
func (s *Source) AddCategory(c *Category) {
|
||||
if s.Categories == nil {
|
||||
s.Categories = make([]*Category, 1)
|
||||
@@ -48,7 +59,18 @@ func (s *Source) AddCategory(c *Category) {
|
||||
}
|
||||
}
|
||||
|
||||
// AddContributor adds the Person as a contributor to the Entry.
|
||||
// DeleteCategory deletes the Category from the Source. It return an error.
|
||||
func (s *Source) DeleteCategory(id int) error {
|
||||
length := len(s.Categories)
|
||||
if id > length {
|
||||
return fmt.Errorf("error deleting category from source %v: id %v out of range %v", s, id, length)
|
||||
}
|
||||
|
||||
s.Categories = append(s.Categories[:id], s.Categories[id+1:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddContributor adds the Person as a contributor to the Source.
|
||||
func (s *Source) AddContributor(c *Person) {
|
||||
if s.Contributors == nil {
|
||||
s.Contributors = make([]*Person, 1)
|
||||
@@ -58,7 +80,18 @@ func (s *Source) AddContributor(c *Person) {
|
||||
}
|
||||
}
|
||||
|
||||
// AddLink adds the Link to the Entry.
|
||||
// DeleteContributor deletes the Person from the Source. It return an error.
|
||||
func (s *Source) DeleteContributor(id int) error {
|
||||
length := len(s.Contributors)
|
||||
if id > length {
|
||||
return fmt.Errorf("error deleting contributor from source %v: id %v out of range %v", s, id, length)
|
||||
}
|
||||
|
||||
s.Contributors = append(s.Contributors[:id], s.Contributors[id+1:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddLink adds the Link to the Source.
|
||||
func (s *Source) AddLink(l *Link) {
|
||||
if s.Links == nil {
|
||||
s.Links = make([]*Link, 1)
|
||||
@@ -68,7 +101,18 @@ func (s *Source) AddLink(l *Link) {
|
||||
}
|
||||
}
|
||||
|
||||
// AddExtension adds the ExtensionElement to the Entry.
|
||||
// DeleteLink deletes the Link from the Source. It return an error.
|
||||
func (s *Source) DeleteLink(id int) error {
|
||||
length := len(s.Links)
|
||||
if id > length {
|
||||
return fmt.Errorf("error deleting link from source %v: id %v out of range %v", s, id, length)
|
||||
}
|
||||
|
||||
s.Links = append(s.Links[:id], s.Links[id+1:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddExtension adds the ExtensionElement to the Source.
|
||||
func (s *Source) AddExtension(e *ExtensionElement) {
|
||||
if s.Extensions == nil {
|
||||
s.Extensions = make([]*ExtensionElement, 1)
|
||||
@@ -78,6 +122,17 @@ func (s *Source) AddExtension(e *ExtensionElement) {
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteExtension deletes the Extension from the Source. It return an error.
|
||||
func (s *Source) DeleteExtension(id int) error {
|
||||
length := len(s.Extensions)
|
||||
if id > length {
|
||||
return fmt.Errorf("error deleting extension from source %v: id %v out of range %v", s, id, length)
|
||||
}
|
||||
|
||||
s.Extensions = append(s.Extensions[:id], s.Extensions[id+1:]...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check checks the Source for incompatibilities with RFC4287. It returns an
|
||||
// error.
|
||||
func (s *Source) Check() error {
|
||||
|
Reference in New Issue
Block a user