新手求解,HTTP如何获取访客IP

package main

import (
“fmt”
//“html/template”
“net/http”
)

func Index(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL.String())
fmt.Println(http.Request{}.RemoteAddr)
}

func main() {
http.HandleFunc(“/“, Index)
err := http.ListenAndServe(“:8080”, nil)

if err != nil {
    fmt.Println("Error: ", err)
}

}

无法得到访客的IP。。求解

共 1 个回复


tmnykf

自己脑残了,直接r.RemoteAddr

# 0