Initial commit
This commit is contained in:
34
radio/trains.go
Normal file
34
radio/trains.go
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user