From f3dae5dfa572cdfd3c18dfbc5be04b96979c9c30 Mon Sep 17 00:00:00 2001 From: wood Date: Thu, 12 Sep 2024 17:21:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B0=E5=AF=8C=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 7327871..b6b7442 100644 --- a/main.go +++ b/main.go @@ -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 { @@ -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) }