From baca39c3213fc323797ca8a1169c59f1f9e72fa2 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Thu, 4 May 2017 08:20:50 +1000 Subject: [PATCH] Hopefully fix out of range issue --- main.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index e71417cc..e6fd7f2f 100644 --- a/main.go +++ b/main.go @@ -118,15 +118,20 @@ func searchHandler(w http.ResponseWriter, r *http.Request) { page := vars["page"] // db params url - maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max")); - if (errConv != nil) { + maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max")) + if errConv != nil { maxPerPage = 50 // default Value maxPerPage - } + } pagenum, _ := strconv.Atoi(html.EscapeString(page)) param1 := r.URL.Query().Get("q") cat := r.URL.Query().Get("c") - param2 := strings.Split(cat, "_")[0] - param3 := strings.Split(cat, "_")[1] + + var param2, param3 string + params := strings.Split(cat, "_") + if len(params) != 0 { + param2 = params[0] + param3 = params[1] + } nbTorrents := 0 @@ -168,11 +173,11 @@ func rootHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) page := vars["page"] - // db params url - maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max")); - if (errConv != nil) { + // db params url + maxPerPage, errConv := strconv.Atoi(r.URL.Query().Get("max")) + if errConv != nil { maxPerPage = 50 // default Value maxPerPage - } + } nbTorrents := 0 pagenum, _ := strconv.Atoi(html.EscapeString(page)) @@ -211,8 +216,8 @@ func main() { cssHandler := http.FileServer(http.Dir("./css/")) jsHandler := http.FileServer(http.Dir("./js/")) - http.Handle("/css/", http.StripPrefix("/css/", cssHandler)) - http.Handle("/js/", http.StripPrefix("/js/", jsHandler)) + http.Handle("/css/", http.StripPrefix("/css/", cssHandler)) + http.Handle("/js/", http.StripPrefix("/js/", jsHandler)) // Routes, router.HandleFunc("/", rootHandler)