duanlu9557 2016-03-25 17:02
浏览 7
已采纳

为什么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>
  • 写回答

1条回答 默认 最新

  • dongmu5920 2016-03-25 17:09
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?