2016-02-19 08:42
浏览 746


I'm reading Go Web Programming by Sau Sheong Chang. Here is a sample code for reading data from a request body:

import (

func bodyfunc(w http.ResponseWriter, r *http.Request) {
    len := r.ContentLength
    body := make([]byte, len)
    fmt.Fprintln(w, string(body))

func main() {
    server := http.Server{
        Addr: "",
    http.HandleFunc("/body", bodyfunc)

By definition, the Body field in the Request struct is actually an io.ReadCloser interface. My question is: The Read method in this interface is just declared but not implemented. Meanwhile the code works well. The implementation of the Read method must have been done somewhere. Where is it?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题