Skip to content

Commit

Permalink
随机
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieYu4994 committed Jan 29, 2021
1 parent e50296a commit 5af0c8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 8 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"fmt"
"math/rand"
"net/http"
"time"
)

func redirectToHD(w http.ResponseWriter, r *http.Request) {
Expand All @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"database/sql"
"fmt"
"net/http"
"time"
)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5af0c8e

Please sign in to comment.