Compare commits
3 Commits
v0.5.0
...
cf131f0bcf
Author | SHA1 | Date | |
---|---|---|---|
cf131f0bcf | |||
ae24db0c08 | |||
8ce7d54d00 |
269
README.md
269
README.md
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
An extensible Atom feed generator library that aims to be very close to RFC4287.
|
An extensible Atom feed generator library that aims to be very close to RFC4287.
|
||||||
It diligently checks for compliance with the standard and provides functions for
|
It diligently checks for compliance with the standard and provides functions for
|
||||||
easy creation and extension of elements.
|
easy creation, extension and deletion of elements.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -14,45 +14,47 @@ go get git.streifling.com/jason/atom@latest
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
This library provides convenient functions to safely create and extend elements
|
### Basic Feed
|
||||||
and attributes of Atom feeds. It also provides checks for all constructs'
|
|
||||||
adherence to RFC4287.
|
This library provides convenient functions to safely create, extend and delete
|
||||||
|
elements and attributes of Atom feeds. It also provides checks for all
|
||||||
|
constructs' adherence to RFC4287.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.streifling.com/jason/atom"
|
"git.streifling.com/jason/atom"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
feed := atom.NewFeed("Example Feed")
|
feed := atom.NewFeed("Example Feed")
|
||||||
if err := feed.Check(); err != nil {
|
if err := feed.Check(); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
author := atom.NewPerson("John Doe")
|
author := atom.NewPerson("John Doe")
|
||||||
author.Email = "john.doe@example.com"
|
author.Email = "john.doe@example.com"
|
||||||
if err := author.Check(); err != nil {
|
if err := author.Check(); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
feed.AddAuthor(author)
|
feed.AddAuthor(author)
|
||||||
|
|
||||||
entry := atom.NewEntry("First Entry")
|
entry := atom.NewEntry("First Entry")
|
||||||
entry.Content = atom.NewContent(atom.InlineText, "text", "This is the content of the first entry.")
|
entry.Content = atom.NewContent(atom.InlineText, "text", "This is the content of the first entry.")
|
||||||
if err := entry.Check(); err != nil {
|
if err := entry.Check(); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
feed.AddEntry(entry)
|
feed.AddEntry(entry)
|
||||||
|
|
||||||
feedString, err := feed.ToXML("utf-8")
|
feedString, err := feed.ToXML("UTF-8")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
fmt.Println(feedString)
|
fmt.Println(feedString)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -63,70 +65,177 @@ provide.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.streifling.com/jason/atom"
|
"git.streifling.com/jason/atom"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
feed := &atom.Feed{
|
feed := &atom.Feed{
|
||||||
Title: &atom.PlainText{
|
Title: &atom.PlainText{
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Text: "Example Feed",
|
Text: "Example Feed",
|
||||||
},
|
},
|
||||||
ID: &atom.ID{URI: "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"},
|
ID: &atom.ID{URI: fmt.Sprint("urn:uuid:", uuid.New())},
|
||||||
Updated: &atom.Date{DateTime: atom.DateTime(now)},
|
Updated: &atom.Date{DateTime: atom.DateTime(now)},
|
||||||
Authors: []*atom.Person{
|
Authors: []*atom.Person{
|
||||||
{
|
{
|
||||||
Name: "John Doe",
|
Name: "John Doe",
|
||||||
Email: "john.doe@example.com",
|
Email: "john.doe@example.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Entries: []*atom.Entry{
|
Entries: []*atom.Entry{
|
||||||
{
|
{
|
||||||
Title: &atom.PlainText{
|
Title: &atom.PlainText{
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Text: "First Entry",
|
Text: "First Entry",
|
||||||
},
|
},
|
||||||
ID: &atom.ID{URI: "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"},
|
ID: &atom.ID{URI: fmt.Sprint("urn:uuid:", uuid.New())},
|
||||||
Updated: &atom.Date{DateTime: atom.DateTime(now)},
|
Updated: &atom.Date{DateTime: atom.DateTime(now)},
|
||||||
Content: &atom.InlineTextContent{
|
Content: &atom.InlineTextContent{
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Text: "This is the content of the first entry.",
|
Text: "This is the content of the first entry.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
feedString, err := feed.ToXML("utf-8")
|
feedString, err := feed.ToXML("UTF-8")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
fmt.Println(feedString)
|
fmt.Println(feedString)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The output of both ways of using it is an RFC4287 compliant Atom feed.
|
The output of both ways of using it is an RFC4287 compliant Atom feed.
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
<author>
|
<author>
|
||||||
<name>John Doe</name>
|
<name>John Doe</name>
|
||||||
<email>john.doe@example.com</email>
|
<email>john.doe@example.com</email>
|
||||||
</author>
|
</author>
|
||||||
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
|
||||||
<title type="text">Example Feed</title>
|
<title type="text">Example Feed</title>
|
||||||
<updated>2024-10-18T05:49:08+02:00</updated>
|
<updated>2024-10-18T05:49:08+02:00</updated>
|
||||||
<entry>
|
<entry>
|
||||||
<content type="text">This is the content of the first entry.</content>
|
<content type="text">This is the content of the first entry.</content>
|
||||||
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
|
||||||
<title type="text">First Entry</title>
|
<title type="text">First Entry</title>
|
||||||
<updated>2006-01-02T15:04:05+07:00</updated>
|
<updated>2006-01-02T15:04:05+07:00</updated>
|
||||||
</entry>
|
</entry>
|
||||||
|
</feed>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Compliance and Error Checking
|
||||||
|
|
||||||
|
All Atom constructs have their own ```construct.Check()``` method. It checks for
|
||||||
|
compliance with RFC4287 and errors. This allows one to be certain that only
|
||||||
|
compliant constructs are added to their respective parent construct. It also
|
||||||
|
means that not the entire feed has to be checked every time a new construct is
|
||||||
|
added. Instead one only checks the current construct and all of its
|
||||||
|
sub-constructs with a single ```construct.Check()``` call.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"git.streifling.com/jason/atom"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
feed := atom.NewFeed("Example Feed")
|
||||||
|
if err := feed.Check(); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
entry := atom.NewEntry("One")
|
||||||
|
entry.Content = atom.NewContent(atom.InlineText, "text", "Entry One")
|
||||||
|
entry.AddAuthor(atom.NewPerson("John Doe"))
|
||||||
|
if err := entry.Check(); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
feed.AddEntry(entry)
|
||||||
|
|
||||||
|
feedString, err := feed.ToXML("UTF-8")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
fmt.Println(feedString)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adding and Deleting Items
|
||||||
|
|
||||||
|
To add elements to any slice one calls the appropriate
|
||||||
|
```someone.AddSomething(toBeAdded)``` method. It returns the item's index
|
||||||
|
number. To delete the item one calls the Delete method.
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"git.streifling.com/jason/atom"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
feed := atom.NewFeed("Feed")
|
||||||
|
if err := feed.Check(); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
e1 := atom.NewEntry("One")
|
||||||
|
e1.Content = atom.NewContent(atom.InlineText, "text", "Entry One")
|
||||||
|
if err := e1.Check(); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
i1 := feed.AddEntry(e1)
|
||||||
|
|
||||||
|
e2 := atom.NewEntry("Two")
|
||||||
|
e2.Content = atom.NewContent(atom.InlineText, "text", "Entry Two")
|
||||||
|
if err := e2.Check(); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
feed.AddEntry(e2)
|
||||||
|
|
||||||
|
if err := feed.DeleteEntry(i1); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
feedString, err := feed.ToXML("UTF-8")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
fmt.Println(feedString)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The output of this example looks like this. It only shows the second entry.
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
|
<id>urn:uuid:ae89d343-b535-447d-ac14-4b80d3e02a2f</id>
|
||||||
|
<title type="text">Example Feed</title>
|
||||||
|
<updated>2024-10-20T14:57:02+02:00</updated>
|
||||||
|
<entry>
|
||||||
|
<content type="text">Entry Two</content>
|
||||||
|
<id>urn:uuid:620c6f73-ee1d-4c1e-be98-b0b1ad7a053f</id>
|
||||||
|
<title type="text">Two</title>
|
||||||
|
<updated>2024-10-20T14:57:02+02:00</updated>
|
||||||
|
</entry>
|
||||||
</feed>
|
</feed>
|
||||||
```
|
```
|
||||||
|
6
atom.go
6
atom.go
@ -16,12 +16,14 @@ type Countable interface {
|
|||||||
*xml.Attr | *Person | *Category | *Link | *ExtensionElement | *Entry
|
*xml.Attr | *Person | *Category | *Link | *ExtensionElement | *Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// addToSlice adds a Countable to to a *[]Countable
|
// addToSlice adds a Countable to to a *[]Countable. It returns an int.
|
||||||
func addToSlice[C Countable](slice *[]C, countable C) {
|
func addToSlice[C Countable](slice *[]C, countable C) int {
|
||||||
if *slice == nil {
|
if *slice == nil {
|
||||||
*slice = make([]C, 0)
|
*slice = make([]C, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
*slice = append(*slice, countable)
|
*slice = append(*slice, countable)
|
||||||
|
return len(*slice) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteFromSlice deletes the Countable with the index from the *[]Countable.
|
// deleteFromSlice deletes the Countable with the index from the *[]Countable.
|
||||||
|
@ -17,9 +17,10 @@ func newCommonAttributes() *CommonAttributes {
|
|||||||
return new(CommonAttributes)
|
return new(CommonAttributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAttribute adds the attribute to the CommonAttributes.
|
// AddAttribute adds the attribute to the CommonAttributes. It returns its index
|
||||||
func (c *CommonAttributes) AddAttribute(name, value string) {
|
// as an int.
|
||||||
addToSlice(&c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value})
|
func (c *CommonAttributes) AddAttribute(name, value string) int {
|
||||||
|
return addToSlice(&c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAttribute deletes the attribute at index from the CommonAttributes. It
|
// DeleteAttribute deletes the attribute at index from the CommonAttributes. It
|
||||||
|
33
entry.go
33
entry.go
@ -66,10 +66,11 @@ func NewEntry(title string) *Entry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAuthor adds the Person as an author to the Entry.
|
// AddAuthor adds the Person as an author to the Entry. It returns its index as
|
||||||
func (e *Entry) AddAuthor(p *Person) {
|
// an int.
|
||||||
addToSlice(&e.Authors, p)
|
func (e *Entry) AddAuthor(p *Person) int {
|
||||||
e.Updated = NewDate(time.Now())
|
e.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&e.Authors, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAuthor deletes the Person at index from the Entry. It return an error.
|
// DeleteAuthor deletes the Person at index from the Entry. It return an error.
|
||||||
@ -82,10 +83,10 @@ func (e *Entry) DeleteAuthor(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCategory adds the Category to the Entry.
|
// AddCategory adds the Category to the Entry. It returns ts index as an int.
|
||||||
func (e *Entry) AddCategory(c *Category) {
|
func (e *Entry) AddCategory(c *Category) int {
|
||||||
addToSlice(&e.Categories, c)
|
|
||||||
e.Updated = NewDate(time.Now())
|
e.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&e.Categories, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteCategory deletes the Category at index from the Entry. It return an
|
// DeleteCategory deletes the Category at index from the Entry. It return an
|
||||||
@ -99,10 +100,11 @@ func (e *Entry) DeleteCategory(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddContributor adds the Person as a contributor to the Entry.
|
// AddContributor adds the Person as a contributor to the Entry. It returns its
|
||||||
func (e *Entry) AddContributor(c *Person) {
|
// index as an int.
|
||||||
addToSlice(&e.Contributors, c)
|
func (e *Entry) AddContributor(c *Person) int {
|
||||||
e.Updated = NewDate(time.Now())
|
e.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&e.Contributors, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteContributor deletes the Person at index from the Entry. It return an
|
// DeleteContributor deletes the Person at index from the Entry. It return an
|
||||||
@ -116,10 +118,10 @@ func (e *Entry) DeleteContributor(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddLink adds the Link to the Entry.
|
// AddLink adds the Link to the Entry. It returns its index as an int.
|
||||||
func (e *Entry) AddLink(l *Link) {
|
func (e *Entry) AddLink(l *Link) int {
|
||||||
addToSlice(&e.Links, l)
|
|
||||||
e.Updated = NewDate(time.Now())
|
e.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&e.Links, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteLink deletes the Link at index from the Entry. It return an error.
|
// DeleteLink deletes the Link at index from the Entry. It return an error.
|
||||||
@ -132,10 +134,11 @@ func (e *Entry) DeleteLink(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddExtension adds the ExtensionElement to the Entry.
|
// AddExtension adds the ExtensionElement to the Entry. It returns its index as
|
||||||
func (e *Entry) AddExtension(x *ExtensionElement) {
|
// an int.
|
||||||
addToSlice(&e.Extensions, x)
|
func (e *Entry) AddExtension(x *ExtensionElement) int {
|
||||||
e.Updated = NewDate(time.Now())
|
e.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&e.Extensions, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteExtension deletes the Extension at index from the Entry. It return an
|
// DeleteExtension deletes the Extension at index from the Entry. It return an
|
||||||
|
37
feed.go
37
feed.go
@ -35,10 +35,11 @@ func NewFeed(title string) *Feed {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAuthor adds the Person as an author to the Feed.
|
// AddAuthor adds the Person as an author to the Feed. It returns its index as
|
||||||
func (f *Feed) AddAuthor(p *Person) {
|
// an int.
|
||||||
addToSlice(&f.Authors, p)
|
func (f *Feed) AddAuthor(p *Person) int {
|
||||||
f.Updated = NewDate(time.Now())
|
f.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&f.Authors, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAuthor deletes the Person at index from the Feed. It return an error.
|
// DeleteAuthor deletes the Person at index from the Feed. It return an error.
|
||||||
@ -51,10 +52,10 @@ func (f *Feed) DeleteAuthor(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCategory adds the Category to the Feed.
|
// AddCategory adds the Category to the Feed. It returns its index as an int.
|
||||||
func (f *Feed) AddCategory(c *Category) {
|
func (f *Feed) AddCategory(c *Category) int {
|
||||||
addToSlice(&f.Categories, c)
|
|
||||||
f.Updated = NewDate(time.Now())
|
f.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&f.Categories, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteCategory deletes the Category at index from the Feed. It return an
|
// DeleteCategory deletes the Category at index from the Feed. It return an
|
||||||
@ -68,10 +69,11 @@ func (f *Feed) DeleteCategory(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddContributor adds the Person as a contributor to the Feed.
|
// AddContributor adds the Person as a contributor to the Feed. It returns its
|
||||||
func (f *Feed) AddContributor(c *Person) {
|
// index as an int.
|
||||||
addToSlice(&f.Contributors, c)
|
func (f *Feed) AddContributor(c *Person) int {
|
||||||
f.Updated = NewDate(time.Now())
|
f.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&f.Contributors, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteContributor deletes the Person at index from the Feed. It return an
|
// DeleteContributor deletes the Person at index from the Feed. It return an
|
||||||
@ -86,9 +88,10 @@ func (f *Feed) DeleteContributor(index int) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddLink adds the Link to the Feed. There should be one Link with Rel "self".
|
// AddLink adds the Link to the Feed. There should be one Link with Rel "self".
|
||||||
func (f *Feed) AddLink(l *Link) {
|
// It returns its index as an int.
|
||||||
addToSlice(&f.Links, l)
|
func (f *Feed) AddLink(l *Link) int {
|
||||||
f.Updated = NewDate(time.Now())
|
f.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&f.Links, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteLink deletes the Link at index from the Feed. It return an error.
|
// DeleteLink deletes the Link at index from the Feed. It return an error.
|
||||||
@ -101,10 +104,10 @@ func (f *Feed) DeleteLink(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddExtension adds the Extension to the Feed.
|
// AddExtension adds the Extension to the Feed. It returns its index as an int.
|
||||||
func (f *Feed) AddExtension(e *ExtensionElement) {
|
func (f *Feed) AddExtension(e *ExtensionElement) int {
|
||||||
addToSlice(&f.Extensions, e)
|
|
||||||
f.Updated = NewDate(time.Now())
|
f.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&f.Extensions, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteExtension deletes the Extension at index from the Feed. It return an
|
// DeleteExtension deletes the Extension at index from the Feed. It return an
|
||||||
@ -118,10 +121,10 @@ func (f *Feed) DeleteExtension(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEntry adds the Entry to the Feed.
|
// AddEntry adds the Entry to the Feed. It returns its index as an int.
|
||||||
func (f *Feed) AddEntry(e *Entry) {
|
func (f *Feed) AddEntry(e *Entry) int {
|
||||||
addToSlice(&f.Entries, e)
|
|
||||||
f.Updated = NewDate(time.Now())
|
f.Updated = NewDate(time.Now())
|
||||||
|
return addToSlice(&f.Entries, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteEntry deletes the Entry at index from the Feed. It return an error.
|
// DeleteEntry deletes the Entry at index from the Feed. It return an error.
|
||||||
|
@ -21,9 +21,10 @@ func NewPerson(name string) *Person {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddExtension adds the Extension to the Person.
|
// AddExtension adds the Extension to the Person. It returns its index as an
|
||||||
func (p *Person) AddExtension(e *ExtensionElement) {
|
// int.
|
||||||
addToSlice(&p.Extensions, e)
|
func (p *Person) AddExtension(e *ExtensionElement) int {
|
||||||
|
return addToSlice(&p.Extensions, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteExtension deletes the Extension at index from the Person. It return an
|
// DeleteExtension deletes the Extension at index from the Person. It return an
|
||||||
|
33
source.go
33
source.go
@ -28,9 +28,10 @@ func NewSource() *Source {
|
|||||||
return &Source{CommonAttributes: newCommonAttributes()}
|
return &Source{CommonAttributes: newCommonAttributes()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAuthor adds the Person as an author to the Source.
|
// AddAuthor adds the Person as an author to the Source. It returns its index as
|
||||||
func (s *Source) AddAuthor(p *Person) {
|
// an int.
|
||||||
addToSlice(&s.Authors, p)
|
func (s *Source) AddAuthor(p *Person) int {
|
||||||
|
return addToSlice(&s.Authors, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAuthor deletes the Person at index from the Source. It return an error.
|
// DeleteAuthor deletes the Person at index from the Source. It return an error.
|
||||||
@ -41,9 +42,9 @@ func (s *Source) DeleteAuthor(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddCategory adds the Category to the Source.
|
// AddCategory adds the Category to the Source. It returns its index as an int.
|
||||||
func (s *Source) AddCategory(c *Category) {
|
func (s *Source) AddCategory(c *Category) int {
|
||||||
addToSlice(&s.Categories, c)
|
return addToSlice(&s.Categories, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteCategory deletes the Category at index from the Source. It return an
|
// DeleteCategory deletes the Category at index from the Source. It return an
|
||||||
@ -55,9 +56,10 @@ func (s *Source) DeleteCategory(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddContributor adds the Person as a contributor to the Source.
|
// AddContributor adds the Person as a contributor to the Source. It returns its
|
||||||
func (s *Source) AddContributor(c *Person) {
|
// index as an int.
|
||||||
addToSlice(&s.Contributors, c)
|
func (s *Source) AddContributor(c *Person) int {
|
||||||
|
return addToSlice(&s.Contributors, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteContributor deletes the Person at index from the Source. It return an
|
// DeleteContributor deletes the Person at index from the Source. It return an
|
||||||
@ -69,9 +71,9 @@ func (s *Source) DeleteContributor(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddLink adds the Link to the Source.
|
// AddLink adds the Link to the Source. It returns its index as an int.
|
||||||
func (s *Source) AddLink(l *Link) {
|
func (s *Source) AddLink(l *Link) int {
|
||||||
addToSlice(&s.Links, l)
|
return addToSlice(&s.Links, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteLink deletes the Link at index from the Source. It return an error.
|
// DeleteLink deletes the Link at index from the Source. It return an error.
|
||||||
@ -82,9 +84,10 @@ func (s *Source) DeleteLink(index int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddExtension adds the ExtensionElement to the Source.
|
// AddExtension adds the ExtensionElement to the Source. It returns its index as
|
||||||
func (s *Source) AddExtension(e *ExtensionElement) {
|
// an int.
|
||||||
addToSlice(&s.Extensions, e)
|
func (s *Source) AddExtension(e *ExtensionElement) int {
|
||||||
|
return addToSlice(&s.Extensions, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteExtension deletes the Extension at index from the Source. It return an
|
// DeleteExtension deletes the Extension at index from the Source. It return an
|
||||||
|
Reference in New Issue
Block a user