From a65aa0a7407bd6d5a24e9b9b2144d0baa1b67f85 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 16 Oct 2024 17:03:23 +0200 Subject: [PATCH] Create NewIcon and appropriate checks --- icon.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/icon.go b/icon.go index aac2b88..89957e1 100644 --- a/icon.go +++ b/icon.go @@ -1,15 +1,26 @@ package atomfeed -import "errors" +import ( + "errors" + "fmt" +) type Icon struct { *CommonAttributes URI URI `xml:"uri"` } +func NewIcon(uri string) *Icon { + return &Icon{URI: URI(uri)} +} + func (i *Icon) Check() error { if i.URI == "" { 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