Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a list of music blog articles #329

Open
wants to merge 12 commits into
base: development
Choose a base branch
from
Open

Conversation

ColinRoitt
Copy link
Contributor

Simple list of articles pulled from mediums RSS feed
Requires one addition to config

Initially open to comment from music team but limited in scope as to what is provided by RSS feed and also I don't want to dump their HTML onto the website.

[music]
	rssFeed = "https://medium.com/feed/@urymusic"

fmt.Printf("Failed to query URL: %v\n", err)
isError = true
}
defer resp.Body.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resp.Body will be nil if there was an error, so this will panic - you'll need to either goto the error return or do an early-return above (where you set isError = true)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oop... good spot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have pushed a fix if you want to double-check it. Currently throwing to 404 page not ideal but does the job when not configured correctly.

controllers/music.go Outdated Show resolved Hide resolved
controllers/music.go Outdated Show resolved Hide resolved
defer resp.Body.Close()

// Read the response body
xmlData, err := io.ReadAll(resp.Body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to look into using the xml Decoder's Decode instead of reading and unmarshaling separately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a performance benefit to that or is it only about readability?
The XML we're expecting is always limited in size so if it's a performance issue it might not be worth the effort.

Copy link
Member

@markspolakovs markspolakovs Jun 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine it's mostly performance since it can decode the XML stream rather than read the whole response into memory, but IMHO the code is marginally cleaner - compare

xmlData, err := io.ReadAll(resp.Body)
if err != nil {
  // ...
}
var response SomeType
err = xml.Unmarshal(xmlData, &response)
if err != nil {
  // ...
}

vs

var response SomeType
err := xml.NewDecoder(resp.Body).Decode(&response)
if err != nil {
  // ...
}

Your call, I've not got a strong opinion either way.

ColinRoitt and others added 2 commits May 26, 2023 18:50
Co-authored-by: Marks Polakovs <github@markspolakovs.me>
@michael-grace
Copy link
Member

  • it should throw a better error if the config is wrong

otherwise, yeah, it's fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants