1. 首页
  2. 主题
  3. Go问与答

关于 *http.requset疑问

hellsam · · 1342 次点击
~~~ type TTT struct { R2 *http.Request } ttt2 := new(TTT) fmt.Fprintln(w, ttt2.R2.Header.Get("Remote_addr")) //以上这么调用是错误的 我想实现自定义个函数 不想 //当然这也显然是没问题的 就是在调用这个test3函数的时候也必须要 声明reg *http.Request 有些函数我不希望这也使用 可否把 reg *http.Request 在内部调用 直接就是 func test3() 然后调用这个方法即可 func test3(reg *http.Request) { req.Header.Get("Remote_addr") } ~~~
~~~ <a href="/user/polaris" title="@polaris">@polaris</a> 我这样写 貌似获取IP为空 不知道为什么 也没报错 type CeshiIP struct { GetIP http.Request } func main() { http.HandleFunc(&#34;/&#34;, test123) err := http.ListenAndServe(&#34;:82&#34;, nil) if err != nil { panic(err) } } func test123(w http.ResponseWriter, r *http.Request) { aa := new(CeshiIP) fmt.Fprintln(w, aa.GetIP.RemoteAddr) //用这个就得不到IP了空白 //fmt.Fprintln(w, r.RemoteAddr) //用这个获取IP正确的 } ~~~
#6
更多评论
polaris
社区,需要你我一同完善!
你看看你发的帖子,你能读通吗?感觉语句不通顺,看不太明白啊~
#2

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中