diff --git a/http.go b/http.go index 67198a4..d49845b 100644 --- a/http.go +++ b/http.go @@ -2,7 +2,9 @@ package main import ( "fmt" + "math/rand" "net/http" + "time" ) func redirectToHD(w http.ResponseWriter, r *http.Request) { @@ -13,6 +15,12 @@ func redirectToUHD(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, picBuffer[0].UHDURL, 302) } +func redirectToRANDOM(w http.ResponseWriter, r *http.Request) { + rand.Seed(time.Now().Unix()) + index := rand.Intn(len(picBuffer) - 1) + http.Redirect(w, r, picBuffer[index].HDURL, 302) +} + func homePage(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, `Here is LassiCat's BingAPI. diff --git a/main.go b/main.go index b9f2695..d80b5e2 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,6 @@ package main import ( "database/sql" - "fmt" "net/http" "time" ) @@ -85,9 +84,8 @@ func main() { http.HandleFunc("/", homePage) http.HandleFunc("/HDRES/", redirectToHD) http.HandleFunc("/UHDRES/", redirectToUHD) + http.HandleFunc("/RANDOM/", redirectToRANDOM) time.Sleep(time.Second) - fmt.Println("Done") - fmt.Println(picBuffer) if conf.EnableTLS { http.ListenAndServeTLS("0.0.0.0:"+conf.Port, conf.CertPath, conf.KeyPath, nil)