为什么http处理程序的参数似乎将其指针向后移动? [重复]
问题描述:
This question already has an answer here:
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
?
</div>
此问题已经存在 在这里有答案 p>
-
在Go HTTP处理程序中,为什么ResponseWriter是一个值,而Request却是一个指针?
5个答案
span>
li>
ul>
div>
我是新手,仍然尝试找出一些问题。 p>
func handler(w http.ResponseWriter,r * http.Request){ } code> pre>
是
w code>而不是指针,而
r code>是指针,因为处理程序函数最终将写入
w code>且仅从
读取 > r code>? p> div>
答
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.