英文:
Why http handler's arguments seem to have their pointer backward?
问题
我是新手,还在努力弄清楚一些事情。
为什么 w
不是一个指针,而 r
是一个指针呢?因为处理函数最终会向 w
写入数据,而只会从 r
中读取数据。
英文:
I am new to go and still trying to figure out a few things.
func handler(w http.ResponseWriter, r *http.Request) {
}
Why is w
not a pointer and on the other hand r
is, since the handler function will end up writing into w
and only read from r
?
答案1
得分: 2
这个问题已经在这个帖子中得到了回答,但为了简洁起见。
w http.ResponseWriter
实际上是一个由非导出指针支持的接口。
而 r *http.Request
是一个实际暴露的结构体。
我建议你点击上面的链接了解更多原因。
英文:
This question has already been answered in this post, but to keep it short.
w http.ResponseWriter
is actually an interface that's backed by a non-exported pointer.
Whereas r *http.Request
is an actual exposed struct.
I'd recommend following the above link to learn more why this is.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论