Skip to content

Commit

Permalink
丰富日志
Browse files Browse the repository at this point in the history
  • Loading branch information
woodchen-ink committed Sep 12, 2024
1 parent e10049f commit f3dae5d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func getCSVContent(path string) ([]string, error) {
}

func handleAPIRequest(w http.ResponseWriter, r *http.Request) {
start := time.Now()
realIP := getRealIP(r)
log.Printf("Handling request from IP: %s\n", realIP)

if time.Since(lastFetchTime) > cacheDuration {
if err := loadCSVPaths(); err != nil {
Expand Down Expand Up @@ -186,6 +186,9 @@ func handleAPIRequest(w http.ResponseWriter, r *http.Request) {

randomURL := fileArray[rng.Intn(len(fileArray))]

log.Printf("Redirecting to %s\n", randomURL)
duration := time.Since(start)
log.Printf("Request: %s %s from %s - Duration: %v - Redirecting to: %s\n",
r.Method, r.URL.Path, realIP, duration, randomURL)

http.Redirect(w, r, randomURL, http.StatusFound)
}

0 comments on commit f3dae5d

Please sign in to comment.