Create NewIcon and appropriate checks

This commit is contained in:
Jason Streifling 2024-10-16 17:03:23 +02:00
parent 566227773e
commit a65aa0a740

13
icon.go
View File

@ -1,15 +1,26 @@
package atomfeed package atomfeed
import "errors" import (
"errors"
"fmt"
)
type Icon struct { type Icon struct {
*CommonAttributes *CommonAttributes
URI URI `xml:"uri"` URI URI `xml:"uri"`
} }
func NewIcon(uri string) *Icon {
return &Icon{URI: URI(uri)}
}
func (i *Icon) Check() error { func (i *Icon) Check() error {
if i.URI == "" { if i.URI == "" {
return errors.New("uri element of icon empty") return errors.New("uri element of icon empty")
} else {
if !isValidURI(i.URI) {
return fmt.Errorf("uri attribute %v of icon not correctly formatted", i.URI)
}
} }
return nil return nil