Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
9445a7c4cd | |||
42416d13e7 | |||
b70ff82141 | |||
3172a4865a | |||
3b3f1f7e41 |
@ -1,4 +1,3 @@
|
||||
# atom-feed
|
||||
# atom
|
||||
|
||||
An extensible implementation of an Atom feed that aims to be very close to RFC4287.
|
||||
|
||||
|
6
atom.go
6
atom.go
@ -82,6 +82,12 @@ func isValidLanguageTag(tag LanguageTag) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// isValidAttribute checks whether an Attribute is valid. It returns a bool.
|
||||
func isValidAttribute(attribute string) bool {
|
||||
regex := regexp.MustCompile(`^[a-zA-Z0-9_]+="[^"]*"$`)
|
||||
return regex.MatchString(attribute)
|
||||
}
|
||||
|
||||
// NewURN generates an new valid IRI based on a UUID. It returns an IRI.
|
||||
func NewURN() IRI {
|
||||
return IRI(fmt.Sprint("urn:uuid:", uuid.New()))
|
||||
|
@ -1,21 +1,27 @@
|
||||
package atom
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
type CommonAttributes struct {
|
||||
Base IRI `xml:"base,attr,omitempty"`
|
||||
Lang LanguageTag `xml:"lang,attr,omitempty"`
|
||||
UndefinedAttributes []*ExtensionAttribute `xml:",any"`
|
||||
UndefinedAttributes []*xml.Attr `xml:",attr,omitempty"`
|
||||
}
|
||||
|
||||
// Check checks the CommonAttributes for incompatibilities with RFC4287. It
|
||||
// returns an error.
|
||||
func (c *CommonAttributes) Check() error {
|
||||
for i, e := range c.UndefinedAttributes {
|
||||
if err := e.Check(); err != nil {
|
||||
return fmt.Errorf("extension attribute %v of common attributes: %v", i, err)
|
||||
}
|
||||
// NewCommonAttributes creates a new set of CommonAttributes. It returns a
|
||||
// *CommonAttributes.
|
||||
func NewCommonAttributes() *CommonAttributes {
|
||||
return new(CommonAttributes)
|
||||
}
|
||||
|
||||
return nil
|
||||
// AddExtensionAttribute adds the ExtensionAttribute to the CommonAttributes.
|
||||
func (c *CommonAttributes) AddExtensionAttribute(name, value string) {
|
||||
if c.UndefinedAttributes == nil {
|
||||
c.UndefinedAttributes = make([]*xml.Attr, 1)
|
||||
c.UndefinedAttributes[0] = &xml.Attr{Name: xml.Name{Local: name}, Value: value}
|
||||
} else {
|
||||
c.UndefinedAttributes = append(c.UndefinedAttributes, &xml.Attr{Name: xml.Name{Local: name}, Value: value})
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// TODO: Is this really correct?
|
||||
type ExtensionAttribute struct {
|
||||
Value any `xml:",attr"`
|
||||
XMLName xml.Name
|
||||
}
|
||||
|
||||
// Check checks the ExtensionAttribute for incompatibilities with RFC4287. It
|
||||
// returns an error.
|
||||
func (e *ExtensionAttribute) Check() error {
|
||||
if e.Value == nil {
|
||||
return errors.New("value element of extension attribute empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
// TODO: Is this really correct?
|
||||
type ExtensionElement struct {
|
||||
Value any `xml:",innerxml"`
|
||||
XMLName xml.Name
|
||||
|
Reference in New Issue
Block a user