2024-10-16 21:28:04 +02:00
|
|
|
package atom
|
2024-10-13 17:19:40 +02:00
|
|
|
|
2024-10-16 17:03:23 +02:00
|
|
|
import (
|
2024-10-17 20:10:18 +02:00
|
|
|
"encoding/xml"
|
2024-10-16 17:03:23 +02:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
2024-10-13 17:19:40 +02:00
|
|
|
|
|
|
|
type Icon struct {
|
2024-10-17 20:10:18 +02:00
|
|
|
XMLName xml.Name `xml:"icon"`
|
2024-10-13 17:19:40 +02:00
|
|
|
*CommonAttributes
|
2024-10-19 12:28:09 +02:00
|
|
|
URI string `xml:",chardata"` // IRI
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
2024-10-19 14:12:51 +02:00
|
|
|
// NewIcon creates a new Icon. It returns a *Icon.
|
|
|
|
func NewIcon(uri string) *Icon {
|
2024-10-19 14:52:19 +02:00
|
|
|
return &Icon{
|
2024-10-20 15:59:46 +02:00
|
|
|
CommonAttributes: NewCommonAttributes(),
|
2024-10-19 14:52:19 +02:00
|
|
|
URI: uri,
|
|
|
|
}
|
2024-10-16 17:03:23 +02:00
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// Check checks the Icon for incompatibilities with RFC4287. It returns an
|
|
|
|
// error.
|
2024-10-13 17:19:40 +02:00
|
|
|
func (i *Icon) Check() error {
|
|
|
|
if i.URI == "" {
|
|
|
|
return errors.New("uri element of icon empty")
|
2024-10-16 17:03:23 +02:00
|
|
|
} else {
|
2024-10-16 17:33:25 +02:00
|
|
|
if !isValidIRI(i.URI) {
|
2024-10-18 19:04:08 +02:00
|
|
|
return fmt.Errorf("uri attribute of icon %v not correctly formatted", i)
|
2024-10-16 17:03:23 +02:00
|
|
|
}
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|