mirror of
https://github.com/woodchen-ink/random-api-go.git
synced 2025-07-18 05:42:01 +08:00
丰富日志
This commit is contained in:
parent
e10049f57c
commit
f3dae5dfa5
7
main.go
7
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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user