Compare commits
5 Commits
ddf5b26a1e
...
d8d0526a05
Author | SHA1 | Date | |
---|---|---|---|
d8d0526a05 | |||
8fc6a10b0d | |||
0b70a8ee10 | |||
da5d955b2d | |||
ee72e91593 |
@ -10,22 +10,17 @@ type Category struct {
|
||||
*CommonAttributes
|
||||
Term string `xml:"term,attr"`
|
||||
Scheme string `xml:"scheme,attr,omitempty"` // IRI
|
||||
Label string `xml:"label,attr,omitempty"`
|
||||
Label string `xml:"label,attr,omitempty"` // Must be unescaped
|
||||
}
|
||||
|
||||
// NewCategory creates a new Category. It returns a *Category.
|
||||
func NewCategory(term string) *Category {
|
||||
return &Category{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Term: term,
|
||||
}
|
||||
}
|
||||
|
||||
// SetLabel sets the Label attribute of the Category.
|
||||
func (c *Category) SetLabel(label string) {
|
||||
c.Label = Unescape(label)
|
||||
}
|
||||
|
||||
// Check checks the Category for incompatibilities with RFC4287. It returns an
|
||||
// error.
|
||||
func (c *Category) Check() error {
|
||||
|
@ -13,7 +13,7 @@ type CommonAttributes struct {
|
||||
|
||||
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
|
||||
// *CommonAttributes.
|
||||
func newCommonAttributes() *CommonAttributes {
|
||||
func NewCommonAttributes() *CommonAttributes {
|
||||
return new(CommonAttributes)
|
||||
}
|
||||
|
||||
|
2
date.go
2
date.go
@ -19,7 +19,7 @@ func DateTime(t time.Time) string {
|
||||
// NewDate creates a new Date. It returns a *Date.
|
||||
func NewDate(t time.Time) *Date {
|
||||
return &Date{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
DateTime: DateTime(t),
|
||||
}
|
||||
}
|
||||
|
72
entry.go
72
entry.go
@ -59,7 +59,7 @@ func (e *Entry) checkAuthors(authorInFeed bool) error {
|
||||
// NewEntry creates a new Entry. It returns a *Entry.
|
||||
func NewEntry(title string) *Entry {
|
||||
return &Entry{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
ID: NewID(NewURN()),
|
||||
Title: NewText("text", title),
|
||||
Updated: NewDate(time.Now()),
|
||||
@ -69,7 +69,12 @@ func NewEntry(title string) *Entry {
|
||||
// AddAuthor adds the Person as an author to the Entry. It returns its index as
|
||||
// an int.
|
||||
func (e *Entry) AddAuthor(p *Person) int {
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&e.Authors, p)
|
||||
}
|
||||
|
||||
@ -79,13 +84,23 @@ func (e *Entry) DeleteAuthor(index int) error {
|
||||
return fmt.Errorf("error deleting author %v from entry %v: %v", index, e.ID.URI, err)
|
||||
}
|
||||
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddCategory adds the Category to the Entry. It returns ts index as an int.
|
||||
func (e *Entry) AddCategory(c *Category) int {
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&e.Categories, c)
|
||||
}
|
||||
|
||||
@ -96,14 +111,24 @@ func (e *Entry) DeleteCategory(index int) error {
|
||||
return fmt.Errorf("error deleting category %v from entry %v: %v", index, e.ID.URI, err)
|
||||
}
|
||||
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddContributor adds the Person as a contributor to the Entry. It returns its
|
||||
// index as an int.
|
||||
func (e *Entry) AddContributor(c *Person) int {
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&e.Contributors, c)
|
||||
}
|
||||
|
||||
@ -114,13 +139,23 @@ func (e *Entry) DeleteContributor(index int) error {
|
||||
return fmt.Errorf("error deleting contributor %v from entry %v: %v", index, e.ID.URI, err)
|
||||
}
|
||||
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddLink adds the Link to the Entry. It returns its index as an int.
|
||||
func (e *Entry) AddLink(l *Link) int {
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&e.Links, l)
|
||||
}
|
||||
|
||||
@ -130,14 +165,24 @@ func (e *Entry) DeleteLink(index int) error {
|
||||
return fmt.Errorf("error deleting link %v from entry %v: %v", index, e.ID.URI, err)
|
||||
}
|
||||
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddExtension adds the ExtensionElement to the Entry. It returns its index as
|
||||
// an int.
|
||||
func (e *Entry) AddExtension(x *ExtensionElement) int {
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&e.Extensions, x)
|
||||
}
|
||||
|
||||
@ -148,7 +193,12 @@ func (e *Entry) DeleteExtension(index int) error {
|
||||
return fmt.Errorf("error deleting extension %v from entry %v: %v", index, e.ID.URI, err)
|
||||
}
|
||||
|
||||
e.Updated = NewDate(time.Now())
|
||||
if e.Updated == nil {
|
||||
e.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
e.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
93
feed.go
93
feed.go
@ -28,7 +28,7 @@ type Feed struct {
|
||||
// NewFeed creates a new Feed. It returns a *Feed.
|
||||
func NewFeed(title string) *Feed {
|
||||
return &Feed{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
ID: NewID(NewURN()),
|
||||
Title: NewText("text", title),
|
||||
Updated: NewDate(time.Now()),
|
||||
@ -38,7 +38,12 @@ func NewFeed(title string) *Feed {
|
||||
// AddAuthor adds the Person as an author to the Feed. It returns its index as
|
||||
// an int.
|
||||
func (f *Feed) AddAuthor(p *Person) int {
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&f.Authors, p)
|
||||
}
|
||||
|
||||
@ -48,13 +53,23 @@ func (f *Feed) DeleteAuthor(index int) error {
|
||||
return fmt.Errorf("error deleting author %v from entry %v: %v", index, f.ID.URI, err)
|
||||
}
|
||||
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddCategory adds the Category to the Feed. It returns its index as an int.
|
||||
func (f *Feed) AddCategory(c *Category) int {
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&f.Categories, c)
|
||||
}
|
||||
|
||||
@ -65,14 +80,24 @@ func (f *Feed) DeleteCategory(index int) error {
|
||||
return fmt.Errorf("error deleting category %v from entry %v: %v", index, f.ID.URI, err)
|
||||
}
|
||||
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddContributor adds the Person as a contributor to the Feed. It returns its
|
||||
// index as an int.
|
||||
func (f *Feed) AddContributor(c *Person) int {
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&f.Contributors, c)
|
||||
}
|
||||
|
||||
@ -83,14 +108,24 @@ func (f *Feed) DeleteContributor(index int) error {
|
||||
return fmt.Errorf("error deleting contributor %v from entry %v: %v", index, f.ID.URI, err)
|
||||
}
|
||||
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddLink adds the Link to the Feed. There should be one Link with Rel "self".
|
||||
// It returns its index as an int.
|
||||
func (f *Feed) AddLink(l *Link) int {
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&f.Links, l)
|
||||
}
|
||||
|
||||
@ -100,13 +135,23 @@ func (f *Feed) DeleteLink(index int) error {
|
||||
return fmt.Errorf("error deleting link %v from entry %v: %v", index, f.ID.URI, err)
|
||||
}
|
||||
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddExtension adds the Extension to the Feed. It returns its index as an int.
|
||||
func (f *Feed) AddExtension(e *ExtensionElement) int {
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&f.Extensions, e)
|
||||
}
|
||||
|
||||
@ -117,13 +162,23 @@ func (f *Feed) DeleteExtension(index int) error {
|
||||
return fmt.Errorf("error deleting extension %v from entry %v: %v", index, f.ID.URI, err)
|
||||
}
|
||||
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddEntry adds the Entry to the Feed. It returns its index as an int.
|
||||
func (f *Feed) AddEntry(e *Entry) int {
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return addToSlice(&f.Entries, e)
|
||||
}
|
||||
|
||||
@ -133,7 +188,12 @@ func (f *Feed) DeleteEntry(index int) error {
|
||||
return fmt.Errorf("error deleting entry %v from entry %v: %v", index, f.ID.URI, err)
|
||||
}
|
||||
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -155,7 +215,12 @@ func (f *Feed) DeleteEntryByURI(uri string) error {
|
||||
}
|
||||
|
||||
f.Entries = append(f.Entries[:index], f.Entries[index+1:]...)
|
||||
f.Updated = NewDate(time.Now())
|
||||
if f.Updated == nil {
|
||||
f.Updated = NewDate(time.Now())
|
||||
} else {
|
||||
f.Updated.DateTime = DateTime(time.Now())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ type Generator struct {
|
||||
// NewGenerator creates a new Generator. It returns a *Generator.
|
||||
func NewGenerator(text string) *Generator {
|
||||
return &Generator{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Text: html.UnescapeString(text),
|
||||
}
|
||||
}
|
||||
|
2
icon.go
2
icon.go
@ -15,7 +15,7 @@ type Icon struct {
|
||||
// NewIcon creates a new Icon. It returns a *Icon.
|
||||
func NewIcon(uri string) *Icon {
|
||||
return &Icon{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
URI: uri,
|
||||
}
|
||||
}
|
||||
|
2
id.go
2
id.go
@ -15,7 +15,7 @@ type ID struct {
|
||||
// NewID creates a new ID. It returns a *ID.
|
||||
func NewID(uri string) *ID {
|
||||
return &ID{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
URI: uri,
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ func newInlineOtherContent(mediaType string, content any) *InlineOtherContent {
|
||||
mediaType, _, _ = mime.ParseMediaType(mediaType)
|
||||
|
||||
return &InlineOtherContent{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Type: mediaType,
|
||||
AnyElement: content,
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ type InlineTextContent struct {
|
||||
// *InlineTextContent.
|
||||
func newInlineTextContent(mediaType, text string) *InlineTextContent {
|
||||
return &InlineTextContent{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Type: mediaType,
|
||||
Text: text,
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ type InlineXHTMLContent struct {
|
||||
// *InlineXHTMLContent.
|
||||
func newInlineXHTMLContent(mediaType string, div *XHTMLDiv) *InlineXHTMLContent {
|
||||
return &InlineXHTMLContent{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Type: mediaType,
|
||||
XHTMLDiv: div,
|
||||
}
|
||||
|
2
link.go
2
link.go
@ -20,7 +20,7 @@ type Link struct {
|
||||
// NewLink creates a new Link. It returns a *Link.
|
||||
func NewLink(href string) *Link {
|
||||
return &Link{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Href: href,
|
||||
}
|
||||
}
|
||||
|
2
logo.go
2
logo.go
@ -14,7 +14,7 @@ type Logo struct {
|
||||
// NewLogo creates a new Logo. It returns a *Logo.
|
||||
func NewLogo(uri string) *Logo {
|
||||
return &Logo{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
URI: uri,
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ func newOutOfLineContent(mediaType, src string) *OutOfLineContent {
|
||||
mediaType, _, _ = mime.ParseMediaType(mediaType)
|
||||
|
||||
return &OutOfLineContent{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Type: mediaType,
|
||||
SRC: src,
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ type Person struct {
|
||||
// NewPerson creates a new Person. It returns a *Person.
|
||||
func NewPerson(name string) *Person {
|
||||
return &Person{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ func (p *PlainText) isText() bool { return true }
|
||||
// newPlainText creates a new PlainText. It returns a *PlainText.
|
||||
func newPlainText(textType, content string) *PlainText {
|
||||
return &PlainText{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Type: textType,
|
||||
Text: content,
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ type Source struct {
|
||||
|
||||
// NewSource creates a new Source. It returns a *Source.
|
||||
func NewSource() *Source {
|
||||
return &Source{CommonAttributes: newCommonAttributes()}
|
||||
return &Source{CommonAttributes: NewCommonAttributes()}
|
||||
}
|
||||
|
||||
// AddAuthor adds the Person as an author to the Source. It returns its index as
|
||||
|
@ -16,7 +16,7 @@ func (x *XHTMLText) isText() bool { return true }
|
||||
// newPlainText creates a new PlainText. It returns a *PlainText.
|
||||
func newXHTMLText(textType, content string) *XHTMLText {
|
||||
return &XHTMLText{
|
||||
CommonAttributes: newCommonAttributes(),
|
||||
CommonAttributes: NewCommonAttributes(),
|
||||
Type: textType,
|
||||
XHTMLDiv: NewXHTMLDiv(content),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user