Correct AddExtension for entry and person

This commit is contained in:
Jason Streifling 2024-10-16 17:38:03 +02:00
parent 082e71a698
commit 39bd0776c5
2 changed files with 19 additions and 6 deletions

View File

@ -1,10 +1,10 @@
package atomfeed
import (
"encoding/xml"
"errors"
"fmt"
"strings"
"time"
)
// It is advisable that each atom:entry element contain a non-empty atom:title
@ -58,8 +58,16 @@ func alternateRelExists(l []*Link) bool {
return false
}
func (e *Entry) AddExtension(name string, value any) {
e.Extensions = append(e.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value})
// AddExtension adds the extension to the entry
func (e *Entry) AddExtension(x *ExtensionElement) {
if e.Extensions == nil {
e.Extensions = make([]*ExtensionElement, 1)
e.Extensions[0] = x
} else {
e.Extensions = append(e.Extensions, x)
}
e.Updated.DateTime = DateTime(time.Now())
}
func (e *Entry) Check() error {

View File

@ -1,7 +1,6 @@
package atomfeed
import (
"encoding/xml"
"errors"
"fmt"
"net/mail"
@ -19,8 +18,14 @@ func NewPerson(name string) *Person {
return &Person{Name: name}
}
func (p *Person) AddExtension(name string, value any) {
p.Extensions = append(p.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value})
// AddExtension adds the extension to the person
func (p *Person) AddExtension(e *ExtensionElement) {
if p.Extensions == nil {
p.Extensions = make([]*ExtensionElement, 1)
p.Extensions[0] = e
} else {
p.Extensions = append(p.Extensions, e)
}
}
func (p *Person) Check() error {