Initial commit

This commit is contained in:
2025-05-22 18:08:15 +02:00
commit 364ffa15de
33 changed files with 900 additions and 0 deletions

34
radio/trains.go Normal file
View File

@@ -0,0 +1,34 @@
package radio
import (
"html/template"
"math/rand"
"net/http"
)
type TrainsTemplateData struct {
PlaylistItems []PlaylistItem
}
func trains(w http.ResponseWriter, r *http.Request) {
trainsPlaylist := getPlaylistOfVideos("PLZoWUOSrw9RfbTAwQ1pTg3rZD-jZJHd9S")
rand.Shuffle(len(trainsPlaylist), func(i, j int) {
trainsPlaylist[i], trainsPlaylist[j] = trainsPlaylist[j], trainsPlaylist[i]
})
templateFile := "templates/trains.tmpl"
files, err := template.New(templateFile).ParseFS(content, templateFile)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = files.ExecuteTemplate(w, "trains.tmpl", TrainsTemplateData{
PlaylistItems: trainsPlaylist,
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}