From 995acf48b97adc4547072d8b9923ba310bf90172 Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com> Date: Sat, 27 Aug 2022 22:10:07 +0200 Subject: [PATCH] Timeout random track fetch --- api.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index 9559536..3140404 100644 --- a/api.go +++ b/api.go @@ -12,6 +12,7 @@ import ( "strconv" "strings" "sync" + "time" ) type API struct { @@ -77,8 +78,12 @@ func (a *API) getFallbackTrack() (*QueueTrackEntry, error) { original: m, }, nil } + func (a *API) getRandomTrack() (*QueueTrackEntry, error) { - response, err := http.DefaultClient.Get(a.config.Queue.RandomSongApi) + + response, err := (&http.Client{ + Timeout: time.Second * 60, + }).Get(a.config.Queue.RandomSongApi) if err != nil { return nil, err } @@ -91,6 +96,7 @@ func (a *API) getRandomTrack() (*QueueTrackEntry, error) { return a.getQueueEntryFromBody(body) } + func (a *API) setNowRandom(nr *QueueTrackEntry) { a.nr = nr if a.config.Queue.NowRandom != "" {