From 39bd0776c547f74acdeb53dffa5f1a31c0983b0e Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 16 Oct 2024 17:38:03 +0200 Subject: [PATCH] Correct AddExtension for entry and person --- entry.go | 14 +++++++++++--- person.go | 11 ++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/entry.go b/entry.go index e4d16f9..201401b 100644 --- a/entry.go +++ b/entry.go @@ -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 { diff --git a/person.go b/person.go index 0a433a0..5eea6ea 100644 --- a/person.go +++ b/person.go @@ -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 {