Skip to content

Commit

Permalink
fix health command
Browse files Browse the repository at this point in the history
  • Loading branch information
slashformotion committed Nov 12, 2023
1 parent 0ce7ef7 commit e92f6c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 9 additions & 8 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ func health(cmd *cobra.Command, args []string) {

// A result after a check
type Result struct {
station urls.Station
valid bool
err string
station urls.Station
valid bool
statusCode string
err error
}

// bubbletea model
Expand Down Expand Up @@ -143,9 +144,8 @@ func createErrorGrid(m healthModel) string {
names := ""
errs := ""
for _, res := range m.errors {
names += "- " + res.station.Name + "\n"
errs += fmt.Sprintf(" : %s", res.err)

names += fmt.Sprintf("- %s (%s)\n", res.station.Name, res.station.Url)
errs += fmt.Sprintf(" : %s\n", res.err.Error())
}

return lipgloss.JoinHorizontal(lipgloss.Top, names, errs)
Expand All @@ -169,14 +169,15 @@ func makeCmd(station urls.Station) tea.Cmd {
}
resp, err := http.Get(station.Url)
if err != nil {
msg.err = err.Error()
msg.err = fmt.Errorf("failed to ping station: %w", err)
return msg
}
defer resp.Body.Close()
msg.statusCode = resp.Status
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
msg.valid = true
} else {
msg.err = fmt.Sprintf("got %d", resp.StatusCode)
msg.err = fmt.Errorf("radio response => %q", resp.Status)
}
return msg
}
Expand Down
3 changes: 2 additions & 1 deletion stations.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
url,"name"
https://walmradio.com:8443/jazz,jazz
http://channels.dinamo.fm/deep-mp3,deep
http://prem2.classicalradio.com/violinworks?b1e8ab696a279ebb68c48cab,violin
http://prem2.classicalradio.com/violinworks?b1e8ab696a279ebb68c48cab,violin
http://prem2.classicalradio.com/violinworks?b1e8ab696a279ebb68c48cab,violin2

0 comments on commit e92f6c5

Please sign in to comment.