For the life of me I thought I was going mad because as far as I could see everything was/is ok with the code in that regards. Out of exasperation I decided to try my application in another browser and found that in Chrome and FF the app works fine, but in Safari for some reason it refreshes the page 3 times. I've tried resetting Safari and turning off extensions in case that was the issue but the same thing happens.
I'm not sure if this is just a quirk with my setup, or potentially my code so I've pasted it here below to have some other eyes look at it. If more code/context is required, please let me know. In essence it takes the user to the index page, the movie page and repeats this process 3 times.
func movieHandler(w http.ResponseWriter, r *http.Request) {
command := r.URL.Query().Get("command")
film := r.URL.Query().Get("movie")
if pageData.Player.Playing == false {
if film == "" {
log.Println("No film was selected")
http.Redirect(w, r, "/", http.StatusFound)
return
}
err := pageData.Player.StartFilm(film)
if err != nil {
log.Printf("Following error occurred: %v
", err)
http.Redirect(w, r, "/", http.StatusFound)
return
}
pageData.CurrentFilm = film
} else if pageData.Player.Playing && (film == "" || pageData.Player.FilmName == film) {
if command == "kill" {
err := pageData.Player.EndFilm()
if err != nil {
log.Printf("Following error occurred: %v
", err)
}
http.Redirect(w, r, "/", http.StatusFound)
return
} else if command != "" {
err := pageData.Player.SendCommandToFilm(command)
if err != nil {
log.Printf("Following error occurred: %v
", err)
}
}
} else {
http.Redirect(w, r, "/", http.StatusFound)
return
}
renderTemplate(w, "movie.html")
}
Note: I'm still an inexperienced coder (especially with go), so additional input on improving this code in any other way is appreciated.