Added pointer checks to check() functions

This commit is contained in:
Jason Streifling 2024-03-05 17:49:07 +01:00
parent 6cd08bb65d
commit 524bf96761

41
rss.go
View File

@ -142,16 +142,35 @@ func (s *Source) check() error {
return nil return nil
} }
func (c *Content) check() error {
if len(c.Value) == 0 {
return fmt.Errorf("error: value not set")
}
return nil
}
func (i *Item) check() error { func (i *Item) check() error {
if len(i.Title) == 0 && len(i.Description) == 0 { if len(i.Title) == 0 && len(i.Description) == 0 {
return fmt.Errorf("error: neither title nor description set") return fmt.Errorf("error: neither title nor description set")
} }
if err := i.Enclosure.check(); err != nil { if i.Enclosure != nil {
return fmt.Errorf("error checking enclosure: %v", err) if err := i.Enclosure.check(); err != nil {
return fmt.Errorf("error checking enclosure: %v", err)
}
} }
if err := i.Source.check(); err != nil {
return fmt.Errorf("error checking source: %v", err) if i.Source != nil {
if err := i.Source.check(); err != nil {
return fmt.Errorf("error checking source: %v", err)
}
}
if i.Content != nil {
if err := i.Content.check(); err != nil {
return fmt.Errorf("error checking content: %v", err)
}
} }
return nil return nil
@ -168,11 +187,16 @@ func (c *Channel) check() error {
return fmt.Errorf("error: description not set") return fmt.Errorf("error: description not set")
} }
if err := c.Image.check(); err != nil { if c.Image != nil {
return fmt.Errorf("error checking image: %v", err) if err := c.Image.check(); err != nil {
return fmt.Errorf("error checking image: %v", err)
}
} }
if err := c.TextInput.check(); err != nil {
return fmt.Errorf("error checking textInput: %v", err) if c.TextInput != nil {
if err := c.TextInput.check(); err != nil {
return fmt.Errorf("error checking textInput: %v", err)
}
} }
for _, item := range c.Items { for _, item := range c.Items {
@ -188,7 +212,6 @@ func (f *Feed) check() error {
if f.Channels == nil { if f.Channels == nil {
return fmt.Errorf("error: feed has no channels") return fmt.Errorf("error: feed has no channels")
} }
for _, channel := range f.Channels { for _, channel := range f.Channels {
if err := channel.check(); err != nil { if err := channel.check(); err != nil {
return fmt.Errorf("error checking channel: %v", err) return fmt.Errorf("error checking channel: %v", err)