从net / http包的文档中:
type Request struct { ... // The host on which the URL is sought. // Per RFC 2616, this is either the value of the Host: header // or the host name given in the URL itself. // It may be of the form "host:port". Host string ...}您的代码的修改后的版本:
func Handler(w http.ResponseWriter, r *http.Request) { fmt.Printf("Req: %s %sn", r.Host, r.URL.Path) }输出示例:
Req: localhost:8888 /



