Change readme accordingly

This commit is contained in:
Jason Streifling 2024-10-19 23:44:36 +02:00
parent 7f30fd5411
commit 4c38753ff7

View File

@ -15,8 +15,8 @@ go get git.streifling.com/jason/atom@latest
## Usage ## Usage
This library provides convenient functions to safely create and extend elements This library provides convenient functions to safely create and extend elements
and attributes of an Atom feed. This is because it can be hard to know all and attributes of Atom feeds. It also provides checks for all constructs'
pitfalls of RFC4287. The intended way of using atom is with these functions. adherence to RFC4287.
```go ```go
package main package main
@ -29,30 +29,28 @@ import (
) )
func main() { func main() {
feed, err := atom.NewFeed("Example Feed") feed := atom.NewFeed("Example Feed")
if err != nil { feed.Title = atom.NewText("text", "Example Feed")
feed.ID = atom.NewID(atom.NewURN())
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 {
log.Fatalln(err)
}
feed.AddAuthor(author) feed.AddAuthor(author)
entry, err := atom.NewEntry("First Entry") entry := atom.NewEntry("First Entry")
if err != nil { entry.ID = atom.NewID(atom.NewURN())
entry.Content = atom.NewContent(atom.InlineText, "text", "This is the content of the first entry.")
if err := entry.Check(); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
content, err := atom.NewContent(atom.InlineText, "text", "This is the content of the first entry.")
if err != nil {
log.Fatalln(err)
}
entry.Content = content
feed.AddEntry(entry) feed.AddEntry(entry)
if err := feed.Check(); err != nil {
log.Fatalln(err)
}
feedString, err := feed.ToXML("utf-8") feedString, err := feed.ToXML("utf-8")
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
@ -62,7 +60,7 @@ func main() {
``` ```
It is also possible to use this library in a way similar to what other libraries It is also possible to use this library in a way similar to what other libraries
would provide. This is, of course, making it easier to make mistakes. provide.
```go ```go
package main package main
@ -115,7 +113,7 @@ func main() {
} }
``` ```
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"?>