package input import ( "strings" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "github.com/mmcdole/gofeed" ) type FeedInput interface { GetArticles() (domain.ArticleEntity, error) } type rssClient struct { SourceRecord domain.SourceEntity } func NewRssClient(sourceRecord domain.SourceEntity) rssClient { client := rssClient{ SourceRecord: sourceRecord, } return client } func (rc rssClient) GetArticles() ([]domain.ArticleEntity, error) { parser := gofeed.NewParser() feed, err := parser.ParseURL(rc.SourceRecord.Url) if err != nil { return nil, err } sourceTags := strings.Split(rc.SourceRecord.Tags, ",") var articles []domain.ArticleEntity for _, post := range feed.Items { article := domain.ArticleEntity{ SourceID: rc.SourceRecord.ID, Title: post.Title, Description: post.Content, Url: post.Link, PubDate: *post.PublishedParsed, //AuthorName: post.Authors[0].Email, } if len(post.Authors) != 0 { article.AuthorName = post.Authors[0].Email } var postTags []string postTags = append(postTags, sourceTags...) postTags = append(postTags, post.Categories...) article.Tags = strings.Join(postTags, ",") /* pageContent, err := getHttpContent(article.Url) if err != nil { continue } htmlNode, err := html.Parse(bytes.NewReader(pageContent)) if err != nil { continue } htmlNode. fmt.Println(htmlNode) */ if post.Image == nil { article.Thumbnail = "" } articles = append(articles, article) } return articles, nil }